Skip to content

Commit a80a2fd

Browse files
authored
1376-V100-Extending-KryptonTaskDialog (#2518)
* 1376-V100-Extending-KryptonTaskDialog - Removes CommonButtons - Integrates CommonButtons in the FooterBar - Adds a separator to each element which can toggled. - Some housekeeping. * 1376-V100-Extending-KryptonTaskDialog - Removes CommonButtons - Integrates CommonButtons in the FooterBar - Adds a separator to each element which can toggled. - Some housekeeping. * 1376-V100-Extending-KryptonTaskDialog - Removes CommonButtons - Integrates CommonButtons in the FooterBar - Adds a separator to each element which can toggled. - Some housekeeping. * 1376-V100-Extending-KryptonTaskDialog - Removes CommonButtons - Integrates CommonButtons in the FooterBar - Adds a separator to each element which can toggled. - Some housekeeping.
1 parent e835c0d commit a80a2fd

34 files changed

+670
-650
lines changed

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonTaskDialog/Elements/KryptonTaskDialogElementBase.cs

Lines changed: 114 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#region BSD License
1+
#region BSD License
22
/*
3-
*
4-
* Original BSD 3-Clause License (https://github.com/ComponentFactory/Krypton/blob/master/LICENSE)
5-
* © Component Factory Pty Ltd, 2006 - 2016, (Version 4.5.0.0) All rights reserved.
63
*
74
* New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
85
* Modifications by Peter Wagner (aka Wagnerp), Simon Coghlan (aka Smurf-IV), Giduac, Ahmed Abdelhameed, tobitege et al. 2025 - 2025. All rights reserved.
@@ -29,6 +26,8 @@ public abstract class KryptonTaskDialogElementBase :
2926
private KryptonPanel _panel;
3027
private bool _panelVisible;
3128
private KryptonTaskDialogDefaults _taskDialogDefaults;
29+
private Bitmap _separator;
30+
private (int FontMinValue, int FontMaxValue, int Adjust75, int Adjust50, int Adjust25) _separatorValues;
3231
#endregion
3332

3433
#region Events
@@ -51,24 +50,32 @@ public KryptonTaskDialogElementBase(KryptonTaskDialogDefaults taskDialogDefaults
5150
{
5251
// Set the data
5352
_taskDialogDefaults = taskDialogDefaults;
53+
_disposed = false;
54+
55+
_separatorValues.FontMinValue = 50;
56+
_separatorValues.FontMaxValue = 255 - 50;
57+
_separatorValues.Adjust75 = 75;
58+
_separatorValues.Adjust50 = 50;
59+
_separatorValues.Adjust25 = 25;
5460

5561
// Although OnGlobalPaletteChanged synchronizes palette changes with the elements,
5662
// The initialisation is done here.
5763
Palette = KryptonManager.CurrentGlobalPalette;
58-
// Execute OnGlobalPaletteChanged once to set the initial palette and wire the PalettePaint event.
59-
OnGlobalPaletteChanged(null!, null!);
6064
// From there the event handler will take over.
6165
KryptonManager.GlobalPaletteChanged += OnGlobalPaletteChanged;
6266

63-
_disposed = false;
64-
6567
_panel = new()
6668
{
67-
Margin = new Padding(0),
68-
Padding = new Padding(0),
69+
Margin = _taskDialogDefaults.NullPadding,
70+
Padding = _taskDialogDefaults.NullMargin,
6971
Visible = false
72+
7073
};
71-
_panelVisible = false;
74+
75+
_panelVisible = false;
76+
_separator = CreateSeparator();
77+
_panel.Paint += OnPanelPaint;
78+
Palette.PalettePaint += OnPalettePaint;
7279

7380
LayoutDirty = false;
7481
}
@@ -115,6 +122,7 @@ protected virtual void OnGlobalPaletteChanged(object? sender, EventArgs e)
115122
if (Palette is not null)
116123
{
117124
Palette.PalettePaint += OnPalettePaint;
125+
_separator = CreateSeparator();
118126
}
119127
}
120128
#endregion
@@ -190,6 +198,23 @@ public sealed override string ToString()
190198
#endregion
191199

192200
#region Public
201+
/// <summary>
202+
/// Displays a separator line at the top of the element.
203+
/// </summary>
204+
public bool ShowSeparator
205+
{
206+
get => field;
207+
208+
set
209+
{
210+
if (field != value)
211+
{
212+
field = value;
213+
_panel.Invalidate();
214+
}
215+
}
216+
}
217+
193218
/// <summary>
194219
/// Returns if the element's layout needs a refresh when visible or before the dialog will be displayed.
195220
/// </summary>
@@ -206,6 +231,11 @@ public sealed override string ToString()
206231
#endregion
207232

208233
#region Private
234+
private void OnPanelPaint(object? sender, PaintEventArgs e)
235+
{
236+
PaintSeparator();
237+
}
238+
209239
private void OnBackColorsChanged()
210240
{
211241
if (BackColor1 != Color.Empty && BackColor2 != Color.Empty)
@@ -228,13 +258,86 @@ protected virtual void OnVisibleChanged()
228258
}
229259
#endregion
230260

261+
#region Private Separator
262+
private Bitmap CreateSeparator()
263+
{
264+
(Color color1, Color color2) colors = GetSeparatorColors();
265+
266+
int width = Defaults.ClientWidth - Defaults.PanelLeft - Defaults.PanelRight;
267+
Rectangle rectangle = new Rectangle(0, 0, width, 2);
268+
Rectangle rectangleTop = new Rectangle(0, 0, width, 1);
269+
Rectangle rectangleBottom = new Rectangle(0, 1, width, 1);
270+
271+
using Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height);
272+
using Brush brush1 = new SolidBrush(colors.color1);
273+
using Brush brush2 = new SolidBrush(colors.color2);
274+
using Graphics graphics = Graphics.FromImage(bitmap);
275+
276+
graphics.FillRectangle(brush1, rectangleTop);
277+
graphics.FillRectangle(brush2, rectangleBottom);
278+
279+
return bitmap.Clone(rectangle, bitmap.PixelFormat);
280+
}
281+
282+
private void PaintSeparator()
283+
{
284+
if (ShowSeparator)
285+
{
286+
using Graphics graphics = Panel.CreateGraphics();
287+
graphics.DrawImage(_separator, Defaults.PanelLeft, 0);
288+
}
289+
}
290+
291+
private (Color, Color) GetSeparatorColors()
292+
{
293+
Color color1;
294+
Color color2;
295+
296+
// If BackColor1 has been set use this for the separator, otherwise fall back to theme colours.
297+
Color tmp = this.BackColor1 != Color.Empty
298+
? this.BackColor1
299+
: Panel.GetResolvedPalette().GetBackColor1(PaletteBackStyle.PanelClient, PaletteState.Normal);
300+
301+
if (tmp.R > _separatorValues.FontMaxValue && tmp.G > _separatorValues.FontMaxValue && tmp.B > _separatorValues.FontMaxValue)
302+
{
303+
// If the colour reaches an upper bound it can't be made lighter.
304+
color1 = Color.FromArgb(tmp.R - _separatorValues.Adjust75, tmp.G - _separatorValues.Adjust75, tmp.B - _separatorValues.Adjust75);
305+
color2 = Color.White;
306+
}
307+
else if (tmp.R < _separatorValues.FontMinValue && tmp.G < _separatorValues.FontMinValue && tmp.B < _separatorValues.FontMinValue)
308+
{
309+
// If the colour reaches a lower bound, it can't be made darker.
310+
color2 = ControlPaint.Light(tmp);
311+
color1 = ControlPaint.Light(Color.LightSlateGray);
312+
}
313+
else if (tmp.R > 150 && tmp.G > 150 && tmp.B > 150)
314+
{
315+
// Colours that are somewhere in the middle need different handling
316+
int r = Math.Min(tmp.R - _separatorValues.Adjust50, 255);
317+
int g = Math.Min(tmp.G - _separatorValues.Adjust50, 255);
318+
int b = Math.Min(tmp.B - _separatorValues.Adjust50, 255);
319+
320+
color1 = Color.FromArgb(r, g, b);
321+
color2 = Color.LightGray;
322+
}
323+
else
324+
{
325+
color1 = ControlPaint.Dark(tmp);
326+
color2 = ControlPaint.Light(tmp);
327+
}
328+
329+
return (color1, color2);
330+
}
331+
#endregion
332+
231333
#region IDispose
232334
/// <inheritdoc/>
233335
protected virtual void Dispose(bool disposing)
234336
{
235337
if (!_disposed && disposing)
236338
{
237339
KryptonManager.GlobalPaletteChanged -= OnGlobalPaletteChanged;
340+
_panel.Paint -= OnPanelPaint;
238341

239342
if (Palette is not null)
240343
{

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonTaskDialog/Elements/KryptonTaskDialogElementCheckBox.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#region BSD License
1+
#region BSD License
22
/*
3-
*
4-
* Original BSD 3-Clause License (https://github.com/ComponentFactory/Krypton/blob/master/LICENSE)
5-
* © Component Factory Pty Ltd, 2006 - 2016, (Version 4.5.0.0) All rights reserved.
63
*
74
* New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
85
* Modifications by Peter Wagner (aka Wagnerp), Simon Coghlan (aka Smurf-IV), Giduac, Ahmed Abdelhameed, tobitege et al. 2025 - 2025. All rights reserved.

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonTaskDialog/Elements/KryptonTaskDialogElementComboBox.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#region BSD License
1+
#region BSD License
22
/*
3-
*
4-
* Original BSD 3-Clause License (https://github.com/ComponentFactory/Krypton/blob/master/LICENSE)
5-
* © Component Factory Pty Ltd, 2006 - 2016, (Version 4.5.0.0) All rights reserved.
63
*
74
* New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
85
* Modifications by Peter Wagner (aka Wagnerp), Simon Coghlan (aka Smurf-IV), Giduac, Ahmed Abdelhameed, tobitege et al. 2025 - 2025. All rights reserved.

0 commit comments

Comments
 (0)