Changeset 15 for Common/DpiScaling.cs
- Timestamp:
- Jun 18, 2024, 12:15:33 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/DpiScaling.cs
r14 r15 6 6 namespace Common 7 7 { 8 class DpiScaling8 public class DpiScaling 9 9 { 10 10 public static float SystemDpi; 11 11 public static bool UseCustomDpi; 12 12 public static float CustomDpi = 96; 13 private static bool _changed; 13 private static bool _changed; 14 14 15 15 public static void ApplyToComponent(Component component) 16 16 { 17 if (component is Control )17 if (component is Control control) 18 18 { 19 foreach (Control child in (component as Control).Controls)19 foreach (Control child in control.Controls) 20 20 { 21 21 ApplyToComponent(child); 22 22 } 23 23 } 24 if (component is ToolStrip )24 if (component is ToolStrip toolStrip) 25 25 { 26 26 //(component as ToolStrip).AutoSize = false; 27 Size newSize = new Size((int)( (component as ToolStrip).ImageScalingSize.Width * CustomDpi / 96F),28 (int)( (component as ToolStrip).ImageScalingSize.Height * CustomDpi / 96F));27 Size newSize = new Size((int)(toolStrip.ImageScalingSize.Width * CustomDpi / 96F), 28 (int)(toolStrip.ImageScalingSize.Height * CustomDpi / 96F)); 29 29 /* foreach (ToolStripItem item in (component as ToolStrip).Items) 30 30 { … … 42 42 } 43 43 } 44 */ (component as ToolStrip).ImageScalingSize = newSize;44 */ toolStrip.ImageScalingSize = newSize; 45 45 46 46 /*(component as ToolStrip).Font = new System.Drawing.Font((component as ToolStrip).Font.FontFamily, 8.25F * customDpi / 96F, … … 52 52 */ 53 53 } 54 if (component is MenuStrip)54 switch (component) 55 55 { 56 (component as MenuStrip).Font = new Font((component as MenuStrip).Font.FontFamily, 8.25F * CustomDpi / 96F, 57 (component as MenuStrip).Font.Style, GraphicsUnit.Point, (component as MenuStrip).Font.GdiCharSet); 58 } 59 if (component is TabControl) 60 { 61 foreach (TabPage tabPage in (component as TabControl).TabPages) 56 case MenuStrip menuStrip: 57 menuStrip.Font = new Font(menuStrip.Font.FontFamily, 8.25F * CustomDpi / 96F, 58 menuStrip.Font.Style, GraphicsUnit.Point, menuStrip.Font.GdiCharSet); 59 break; 60 case TabControl tabControl: 62 61 { 63 ApplyToComponent(tabPage); 62 foreach (TabPage tabPage in tabControl.TabPages) 63 { 64 ApplyToComponent(tabPage); 65 } 66 67 break; 64 68 } 65 } 66 if (component is ToolStripItem) 67 { 68 (component as ToolStripItem).Font = new Font((component as ToolStripItem).Font.FontFamily, 8.25F * CustomDpi / 96F, 69 (component as ToolStripItem).Font.Style, GraphicsUnit.Point, (component as ToolStripItem).Font.GdiCharSet); 69 case ToolStripItem toolStripItem: 70 toolStripItem.Font = new Font(toolStripItem.Font.FontFamily, 8.25F * CustomDpi / 96F, 71 toolStripItem.Font.Style, GraphicsUnit.Point, toolStripItem.Font.GdiCharSet); 72 break; 70 73 } 71 74 } … … 84 87 form.Font.Style, GraphicsUnit.Point, form.Font.GdiCharSet); 85 88 ApplyToComponent(form); 86 } 89 } 87 90 } 88 91 … … 114 117 { 115 118 if (Application.UserAppDataRegistry == null) return; 116 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey, true) ;117 if (regKey == null) regKey =Application.UserAppDataRegistry.CreateSubKey(regSubKey);119 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey, true) ?? 120 Application.UserAppDataRegistry.CreateSubKey(regSubKey); 118 121 119 122 regKey.SetValueInt("CustomDpiEnabled", (int)CustomDpi);
Note:
See TracChangeset
for help on using the changeset viewer.