更改字体和字体大小的最简单方法

Ari*_*ule 49 c# fonts winforms

这是用C#更改字体大小的最简单方法.

使用java,可以通过使用必要的参数调用Font构造函数来轻松完成.

JLabel lab  = new JLabel("Font Bold at 24");
lab.setFont(new Font("Serif", Font.BOLD, 24));
Run Code Online (Sandbox Code Playgroud)

Ari*_*ion 86

也许是这样的:

yourformName.YourLabel.Font = new Font("Arial", 24,FontStyle.Bold);
Run Code Online (Sandbox Code Playgroud)

或者,如果您与表单位于同一个类中,则只需执行以下操作:

YourLabel.Font = new Font("Arial", 24,FontStyle.Bold);
Run Code Online (Sandbox Code Playgroud)

构造函数需要不同的参数(所以选择你的毒药).像这样:

Font(Font, FontStyle)   
Font(FontFamily, Single)
Font(String, Single)
Font(FontFamily, Single, FontStyle)
Font(FontFamily, Single, GraphicsUnit)
Font(String, Single, FontStyle)
Font(String, Single, GraphicsUnit)
Font(FontFamily, Single, FontStyle, GraphicsUnit)
Font(String, Single, FontStyle, GraphicsUnit)
Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)
Font(String, Single, FontStyle, GraphicsUnit, Byte)
Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)
Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)
Run Code Online (Sandbox Code Playgroud)

参考这里


小智 20

使用此选项仅更改字体大小而不是字体名称

label1.Font = new System.Drawing.Font(label1.Font.Name, 24F);
Run Code Online (Sandbox Code Playgroud)


Nir*_*ngh 8

使用字体类设置控件的字体和样式.

尝试字体构造函数(字符串,单个)

Label lab  = new Label();
lab.Text ="Font Bold at 24";
lab.Font = new Font("Arial", 20);
Run Code Online (Sandbox Code Playgroud)

要么

lab.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold);
Run Code Online (Sandbox Code Playgroud)

要获得已安装的字体,请参阅此内容 - .NET System.Drawing.Font - 获取可用的大小和样式


Hab*_*bib 5

这应该做(大胆);

label1.Font = new Font("Serif", 24,FontStyle.Bold);
Run Code Online (Sandbox Code Playgroud)