Default font for Windows Forms application

后端 未结 9 1367
有刺的猬
有刺的猬 2020-12-08 07:06

Every time that I create a new form in my application, it uses the \"Microsoft Sans Serif, 8.25pt\" font by default. I\'m not changing it because I know that in this case my

9条回答
  •  死守一世寂寞
    2020-12-08 07:33

    The controls inside the group box are indeed not affected by the form's Font property. The reason is that controls in container controls are treated as children of the container controls like groupbox, but not children of the main form. In order for all controls including those in groupboxes to scale properly, you can use code similar to below:

            foreach (Control ctr in this.Controls)
            {
                ctr.Font = SystemFonts.IconTitleFont;
    
                // controls in groupboxes are not child of main form
                if (ctr.HasChildren)
                {
                    foreach (Control childControl in ctr.Controls)
                    {
                        childControl.Font = SystemFonts.IconTitleFont;
                    }
                }        
            }
    

提交回复
热议问题