如何在C#中更改所有表单的字体和颜色 [英] How can I change font and color of the all forms in C#

查看:88
本文介绍了如何在C#中更改所有表单的字体和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改所有表单的字体,但是如果可以使用class。

 使用系统; 
使用 System.Collections.Generic;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;

命名空间 UserControl
{
class SetFont
{
public SetFont()
{

}
public static void SetFontFinal()
{
string fontName = Cambria;
字体testFont = 字体(fontName, 16 .0f,FontStyle.Regular,
GraphicsUnit.Pixel);
// 字体存在,请使用它。
this .Font = testFont;

}
}


}





我尝试了什么:



我试过但它不起作用。所以你建议什么?

谢谢。

解决方案

创建基类并添加所有常用设置并将所有 Forms 转换为从此基类继承



  public   partial   class  BaseForm:表格
{
public BaseForm()
{

string fontName = 宋体;
字体commonFont = new 字体(fontName, 16 .0f,FontStyle.Underline,GraphicsUnit。像素);
this .Font = commonFont;
}


}







< pre lang =C#> public partial class Form1:BaseForm



  public  部分  Form2:BaseForm 



 < span class =code-keyword> public   partial   class  Form3:BaseForm 


How can I change the font of all the forms but if it is possible to use class.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UserControl
{
    class SetFont
    {
        public SetFont()
        {

        }
        public static void SetFontFinal()
        {
            string fontName = "Cambria";
           Font testFont = new Font(fontName, 16.0f, FontStyle.Regular,
                         GraphicsUnit.Pixel);
                // The font exists, so use it.
                this.Font = testFont;
           
        }
    }
    

}



What I have tried:

I tried but it doesn't work.So what do you suggest ?
Thank you.

解决方案

Create a Base Class and add all the common settings to it and make all the Forms to inherit from this base class

public partial class BaseForm : Form
   {
       public BaseForm()
       {

           string fontName = "verdana";
           Font commonFont = new Font(fontName, 16.0f, FontStyle.Underline, GraphicsUnit.Pixel);
           this.Font = commonFont;
       }


   }




public partial class Form1 : BaseForm


public partial class Form2 : BaseForm


public partial class Form3 : BaseForm


这篇关于如何在C#中更改所有表单的字体和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆