Skip to content

Commit 1a5a164

Browse files
authored
Merge pull request #213 from Krypton-Suite/alpha-toolkit-controls-rtl
* Touchscreen enhancements
2 parents 3c7b02a + 601b8e7 commit 1a5a164

File tree

1 file changed

+43
-0
lines changed
  • Source/Krypton Components/Krypton.Toolkit/Controls Toolkit

1 file changed

+43
-0
lines changed

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ or PaletteContentStyle.HeaderCustom2
114114

115115
return base.GetContentLongTextH(style, state);
116116
}
117+
118+
public override int GetMetricInt(KryptonForm? owningForm, PaletteState state, PaletteMetricInt metric)
119+
{
120+
// Scale control box button edge inset when touchscreen support is enabled
121+
if (metric == PaletteMetricInt.HeaderButtonEdgeInsetForm && KryptonManager.UseTouchscreenSupport)
122+
{
123+
int baseValue = base.GetMetricInt(owningForm, state, metric);
124+
float scaleFactor = KryptonManager.TouchscreenScaleFactor;
125+
return (int)Math.Round(baseValue * scaleFactor);
126+
}
127+
128+
return base.GetMetricInt(owningForm, state, metric);
129+
}
130+
131+
public override Padding GetMetricPadding(KryptonForm? owningForm, PaletteState state, PaletteMetricPadding metric)
132+
{
133+
// Scale control box button padding when touchscreen support is enabled
134+
if (metric == PaletteMetricPadding.HeaderButtonPaddingForm && KryptonManager.UseTouchscreenSupport)
135+
{
136+
Padding basePadding = base.GetMetricPadding(owningForm, state, metric);
137+
float scaleFactor = KryptonManager.TouchscreenScaleFactor;
138+
return new Padding(
139+
(int)Math.Round(basePadding.Left * scaleFactor),
140+
(int)Math.Round(basePadding.Top * scaleFactor),
141+
(int)Math.Round(basePadding.Right * scaleFactor),
142+
(int)Math.Round(basePadding.Bottom * scaleFactor));
143+
}
144+
145+
return base.GetMetricPadding(owningForm, state, metric);
146+
}
117147
}
118148

119149
/// <summary>
@@ -313,6 +343,7 @@ public KryptonForm()
313343
// Hook into global static events
314344
KryptonManager.GlobalUseThemeFormChromeBorderWidthChanged += OnGlobalUseThemeFormChromeBorderWidthChanged;
315345
KryptonManager.GlobalPaletteChanged += OnGlobalPaletteChanged;
346+
KryptonManager.GlobalTouchscreenSupportChanged += OnGlobalTouchscreenSupportChanged;
316347

317348
// Create the view manager instance
318349
ViewManager = new ViewManager(this, _drawDocker);
@@ -560,6 +591,7 @@ protected override void Dispose(bool disposing)
560591
// Unhook from the global static events
561592
KryptonManager.GlobalPaletteChanged -= OnGlobalPaletteChanged;
562593
KryptonManager.GlobalUseThemeFormChromeBorderWidthChanged -= OnGlobalUseThemeFormChromeBorderWidthChanged;
594+
KryptonManager.GlobalTouchscreenSupportChanged -= OnGlobalTouchscreenSupportChanged;
563595

564596
// #1979 Temporary fix
565597
base.PaletteChanged -= (s, e) => _internalKryptonPanel.PaletteMode = PaletteMode;
@@ -2818,6 +2850,17 @@ private void OnGlobalPaletteChanged(object? sender, EventArgs e)
28182850
}
28192851
}
28202852

2853+
private void OnGlobalTouchscreenSupportChanged(object? sender, EventArgs e)
2854+
{
2855+
// Refresh buttons to apply new touchscreen scaling
2856+
_buttonManager?.RecreateButtons();
2857+
RecalcNonClient();
2858+
if (IsHandleCreated)
2859+
{
2860+
BeginInvoke(new System.Windows.Forms.MethodInvoker(RecalcNonClient));
2861+
}
2862+
}
2863+
28212864
/// <summary>Updates the title style.</summary>
28222865
/// <param name="titleStyle">The title style.</param>
28232866
private void UpdateTitleStyle(KryptonFormTitleStyle titleStyle)

0 commit comments

Comments
 (0)