Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Documents/Changelog/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## 2026-11-xx - Build 2611 (V110 Nightly) - November 2026

* Resolved/Implemented [#2844](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2844), Touchscreen High DPI scaling
* Implemented [#2808](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2808), Move `KryptonToastNotification` feature to `Krypton.Utilities`
* Implemented [#2572](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2572), Autocomplete control/menu
- To use, you will need to download the `Krypton.Standard.Toolkit` NuGet package, as this control is part of the `Krypton.Utilities` assembly.
* Implemented [#2812](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2812), Code Editor Control
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,45 @@ private void OnJumpListChanged()

private void UpdateDpiFactors()
{
// Invalidate the global DPI cache to ensure fresh values are calculated
KryptonManager.InvalidateDpiCache();

// Use per-monitor DPI for proper high DPI and touchscreen scaling support
IntPtr hWnd = IsHandleCreated ? Handle : IntPtr.Zero;

if (hWnd != IntPtr.Zero)
{
try
{
// Try to use GetDpiForWindow for per-monitor DPI awareness (Windows 10 version 1607+)
uint dpi = PI.GetDpiForWindow(hWnd);
if (dpi > 0)
{
FactorDpiX = dpi / 96f;
FactorDpiY = dpi / 96f;
return;
}
}
catch
{
// GetDpiForWindow may not be available on older Windows versions
}

// Fallback to window's Graphics DPI
try
{
using Graphics graphics = Graphics.FromHwnd(hWnd);
FactorDpiX = graphics.DpiX / 96f;
FactorDpiY = graphics.DpiY / 96f;
return;
}
catch
{
// Continue to primary monitor fallback
}
}

// Fallback
// Do not use the control dpi, as these values are being used to target the screen
IntPtr screenDc = PI.GetDC(IntPtr.Zero);
if (screenDc != IntPtr.Zero)
Expand Down
57 changes: 57 additions & 0 deletions Source/Krypton Components/Krypton.Toolkit/View Base/ViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,53 @@ public float FactorDpiX

private void InitialiseFactors()
{
// Try to get per-monitor DPI from the owning control for proper high DPI support
Control? owningControl = OwningControl;
IntPtr hWnd = IntPtr.Zero;

if (owningControl != null && owningControl.IsHandleCreated)
{
hWnd = owningControl.Handle;
}
else if (Component is Control componentControl && componentControl.IsHandleCreated)
{
hWnd = componentControl.Handle;
}

// Use per-monitor DPI if we have a window handle (supports high DPI and touchscreen scaling)
if (hWnd != IntPtr.Zero)
{
try
{
// Try to use GetDpiForWindow for per-monitor DPI awareness (Windows 10 version 1607+)
uint dpi = PI.GetDpiForWindow(hWnd);
if (dpi > 0)
{
_factorDpiX = dpi / 96f;
_factorDpiY = dpi / 96f;
return;
}
}
catch
{
// GetDpiForWindow may not be available on older Windows versions
}

// Fallback to window's Graphics DPI
try
{
using Graphics graphics = Graphics.FromHwnd(hWnd);
_factorDpiX = graphics.DpiX / 96f;
_factorDpiY = graphics.DpiY / 96f;
return;
}
catch
{
// Continue to primary monitor fallback
}
}

// Fallback
// This does mean that the app will not change it's dpi awareness until restarted !
// Do not use the control dpi, as these values are being used to target the screen
var screenDc = PI.GetDC(IntPtr.Zero);
Expand Down Expand Up @@ -274,6 +321,16 @@ public float FactorDpiY
}
}

/// <summary>
/// Invalidates the cached DPI factors, forcing them to be recalculated on the next access.
/// Call this method when the DPI changes (e.g., when the window is moved to a different monitor).
/// </summary>
public void InvalidateDpiFactors()
{
_factorDpiX = 0f;
_factorDpiY = 0f;
}

#endregion

#region Component
Expand Down
1 change: 1 addition & 0 deletions Source/Krypton Components/TestForm/StartScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void AddButtons()
CreateButton("Taskbar Overlay Icon Test", "Comprehensive demonstration of taskbar overlay icons on KryptonForm with configurable icons, descriptions, and interactive examples.", typeof(TaskbarOverlayIconTest));
CreateButton("Theme Controls", string.Empty, typeof(ThemeControlExamples));
CreateButton("TextBox Validating Test", "Tests fix for Validating event duplication bug #2801", typeof(KryptonTextBoxValidatingTest));
CreateButton("Touchscreen + High DPI Demo", "Comprehensive demonstration of touchscreen support with per-monitor high DPI scaling (Issue #2844).", typeof(TouchscreenHighDpiDemo));
CreateButton("RichTextBox Formatting Test", "Tests fix for RichTextBox formatting preservation when palette changes (Issue #2832)", typeof(RichTextBoxFormattingTest));
CreateButton("RTL Layout Test", "Test for RTL compliance", typeof(RTLFormBorderTest));
CreateButton("Toast", "For breakfast....?", typeof(ToastNotificationTestChoice));
Expand Down
Loading
Loading