From dc37ad4025793eafef31062d9da2c1cacf36913f Mon Sep 17 00:00:00 2001 From: Simon Coghlan Date: Mon, 16 Dec 2024 15:20:08 +0000 Subject: [PATCH] - Make it Net4.62 compliant --- .../Krypton.Navigator/Palette/NavigatorHeader.cs | 4 ++++ .../Group Contents/KryptonRibbonGroupItem.cs | 4 ++++ .../View Layout/ViewLayoutRibbonTabsArea.cs | 4 ++++ .../ButtonSpec/ButtonSpecRemapByContentBase.cs | 2 +- .../ContextMenu/KryptonContextMenuItemBase.cs | 4 ++++ .../Krypton.Toolkit/Controls Toolkit/KryptonForm.cs | 4 ++++ .../Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs | 4 ++++ .../Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs | 4 ++++ .../Controls Toolkit/KryptonHeaderGroup.cs | 4 ++++ .../Krypton.Toolkit/Controls Visuals/VisualControlBase.cs | 4 ++++ .../Krypton.Toolkit/General/PlatformInvoke.cs | 4 ++++ .../Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs | 5 ++--- .../Krypton.Toolkit/View Layout/ViewLayoutMonths.cs | 8 ++++++-- 13 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs index caeae7080..4d00b0b45 100644 --- a/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs +++ b/Source/Krypton Components/Krypton.Navigator/Palette/NavigatorHeader.cs @@ -67,7 +67,11 @@ public NavigatorHeader([DisallowNull] KryptonNavigator navigator, private float GetDpiFactor() { +#if NET462 + return PI.GetDpiForWindow(_navigator.Handle) / 96F; +#else return _navigator.DeviceDpi / 96F; +#endif } #endregion diff --git a/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs b/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs index 0d154973a..267c6826a 100644 --- a/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs +++ b/Source/Krypton Components/Krypton.Ribbon/Group Contents/KryptonRibbonGroupItem.cs @@ -48,7 +48,11 @@ protected KryptonRibbonGroupItem() => private float GetDpiFactor() { return (Ribbon != null) +#if NET462 + ? PI.GetDpiForWindow(Ribbon.Handle) / 96F +#else ? Ribbon.DeviceDpi / 96F +#endif : 1.0f; } diff --git a/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs b/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs index b188a3c15..6640a21fd 100644 --- a/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs +++ b/Source/Krypton Components/Krypton.Ribbon/View Layout/ViewLayoutRibbonTabsArea.cs @@ -548,7 +548,11 @@ private void CreateViewElements(PaletteRedirect? redirect) private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } diff --git a/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs b/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs index 1c0d66f9e..2e7a7ef5a 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ButtonSpec/ButtonSpecRemapByContentBase.cs @@ -32,7 +32,7 @@ protected ButtonSpecRemapByContentBase(PaletteBase? target, : base(target) { Debug.Assert(buttonSpec != null); - _buttonSpec = buttonSpec; + _buttonSpec = buttonSpec!; } #endregion diff --git a/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs b/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs index c7d88ef60..ddb7f5f14 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ContextMenu/KryptonContextMenuItemBase.cs @@ -58,7 +58,11 @@ protected KryptonContextMenuItemBase() private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs index eb8b56e69..4c559f0be 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs @@ -204,7 +204,11 @@ public KryptonForm() private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs index ad3f7e70f..7d14f1621 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonGroupBox.cs @@ -109,7 +109,11 @@ public KryptonGroupBox() private float GetDpiFactor() { return (Panel != null) +#if NET462 + ? PI.GetDpiForWindow(Panel.Handle) / 96F +#else ? Panel.DeviceDpi / 96F +#endif : 1f; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs index 28c28c1cb..6030da753 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeader.cs @@ -112,7 +112,11 @@ public KryptonHeader() private float GetDpiFactor() { +#if NET462 + return PI.GetDpiForWindow(Handle) / 96F; +#else return DeviceDpi / 96F; +#endif } /// diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs index b6a21e05f..ff6e5245a 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonHeaderGroup.cs @@ -211,7 +211,11 @@ public KryptonHeaderGroup() private float GetDpiFactor() { return (Panel != null) +#if NET462 + ? PI.GetDpiForWindow(Panel.Handle) / 96F +#else ? Panel.DeviceDpi / 96F +#endif : 1f; } diff --git a/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs b/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs index 7aa6a2e1d..52f420b35 100644 --- a/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs +++ b/Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualControlBase.cs @@ -128,7 +128,11 @@ protected VisualControlBase() private float GetDpiFactor() { +#if NET462 + return PI.GetDpiForWindow(Handle) / 96F; +#else return DeviceDpi / 96F; +#endif } /// diff --git a/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs b/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs index 70d45353f..b7db30330 100644 --- a/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs +++ b/Source/Krypton Components/Krypton.Toolkit/General/PlatformInvoke.cs @@ -2839,6 +2839,10 @@ private static KEY_ GetKeyState(Keys key) #endregion #region Static User32 + [DllImport(Libraries.User32)] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + internal static extern uint GetDpiForWindow(IntPtr hWnd); + [DllImport(Libraries.User32)] [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] internal static extern BOOL EndDialog(IntPtr hDlg, IntPtr nResult); diff --git a/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs b/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs index b356a6fdf..b87f1ddc0 100644 --- a/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs +++ b/Source/Krypton Components/Krypton.Toolkit/ShellDialogs/ShellDialogWrapper.cs @@ -88,8 +88,7 @@ private protected virtual void WndMessage(object sender, CWPRETSTRUCT e, out boo if (e.message == PI.WM_.INITDIALOG) { #if NET462 - using var g = _commonDialogHandler._wrapperForm.CreateGraphics(); - _scaleFactor = g.DpiX / 96.0f; + _scaleFactor = PI.GetDpiForWindow(_commonDialogHandler._wrapperForm.Handle) / 96F; #else _scaleFactor = _commonDialogHandler._wrapperForm.DeviceDpi / 96.0f; #endif @@ -178,7 +177,7 @@ private protected virtual bool WndActivated(object sender, CbtEventArgs e) return true; } - #endregion Do_CBT +#endregion Do_CBT /// /// Runs a common dialog box, parented to the given IWin32Window. diff --git a/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs b/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs index 245688e05..2b7f36f6e 100644 --- a/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs +++ b/Source/Krypton Components/Krypton.Toolkit/View Layout/ViewLayoutMonths.cs @@ -128,7 +128,11 @@ public ViewLayoutMonths(IContextMenuProvider provider, private float GetDpiFactor() { return (_visualPopupToolTip != null) +#if NET462 + ? PI.GetDpiForWindow(_visualPopupToolTip.Handle) / 96F +#else ? _visualPopupToolTip.DeviceDpi / 96F +#endif : 1F; } @@ -480,10 +484,10 @@ public Size GetSingleMonthSize([DisallowNull] ViewLayoutContext context) { Debug.Assert(context != null); - SyncData(context); + SyncData(context!); SyncMonths(); - return this[1].GetPreferredSize(context); + return this[1].GetPreferredSize(context!); } ///