Changeset 15 for Common/DpiScaling.cs


Ignore:
Timestamp:
Jun 18, 2024, 12:15:33 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/DpiScaling.cs

    r14 r15  
    66namespace Common
    77{
    8     class DpiScaling
     8    public class DpiScaling
    99    {
    1010        public static float SystemDpi;
    1111        public static bool UseCustomDpi;
    1212        public static float CustomDpi = 96;
    13         private static bool _changed;       
     13        private static bool _changed;
    1414
    1515        public static void ApplyToComponent(Component component)
    1616        {
    17             if (component is Control)
     17            if (component is Control control)
    1818            {
    19                 foreach (Control child in (component as Control).Controls)
     19                foreach (Control child in control.Controls)
    2020                {
    2121                    ApplyToComponent(child);
    2222                }
    2323            }
    24             if (component is ToolStrip)
     24            if (component is ToolStrip toolStrip)
    2525            {
    2626                //(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));
    2929/*                foreach (ToolStripItem item in (component as ToolStrip).Items)
    3030                {
     
    4242                    }
    4343                }
    44 */              (component as ToolStrip).ImageScalingSize = newSize;
     44*/              toolStrip.ImageScalingSize = newSize;
    4545
    4646                /*(component as ToolStrip).Font = new System.Drawing.Font((component as ToolStrip).Font.FontFamily, 8.25F * customDpi / 96F,
     
    5252                */
    5353            }
    54             if (component is MenuStrip)
     54            switch (component)
    5555            {
    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:
    6261                {
    63                     ApplyToComponent(tabPage);
     62                    foreach (TabPage tabPage in tabControl.TabPages)
     63                    {
     64                        ApplyToComponent(tabPage);
     65                    }
     66
     67                    break;
    6468                }
    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;
    7073            }
    7174        }
     
    8487                    form.Font.Style, GraphicsUnit.Point, form.Font.GdiCharSet);
    8588                ApplyToComponent(form);
    86             }           
     89            }
    8790        }
    8891
     
    114117        {
    115118            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);
    118121
    119122            regKey.SetValueInt("CustomDpiEnabled", (int)CustomDpi);
Note: See TracChangeset for help on using the changeset viewer.