C# 更改字体和字体大小的最简单方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10173147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easiest way to change font and font size
提问by Arianule
which is the easiest way to change Font size with C#.
这是使用 C# 更改字体大小的最简单方法。
with java it can all be done easily by calling Font constructor with necessary arguments.
使用 java 可以通过使用必要的参数调用 Font 构造函数来轻松完成。
JLabel lab = new JLabel("Font Bold at 24");
lab.setFont(new Font("Serif", Font.BOLD, 24));
采纳答案by Arion
Maybe something like this:
也许是这样的:
yourformName.YourLabel.Font = new Font("Arial", 24,FontStyle.Bold);
Or if you are in the same class as the form then simply do this:
或者,如果您与表单在同一班级,则只需执行以下操作:
YourLabel.Font = new Font("Arial", 24,FontStyle.Bold);
The constructor takes diffrent parameters (so pick your poison). Like this:
构造函数采用不同的参数(所以选择你的毒药)。像这样:
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)
Reference here
参考这里
回答by Habib
This should do it (bold as well);
这应该这样做(也大胆);
label1.Font = new Font("Serif", 24,FontStyle.Bold);
回答by Niranjan Singh
Use the Font Classto set the control's font and styles.
使用Font Class来设置控件的字体和样式。
Try Font Constructor (String, Single)
Label lab = new Label();
lab.Text ="Font Bold at 24";
lab.Font = new Font("Arial", 20);
or
或者
lab.Font = new Font(FontFamily.GenericSansSerif,
12.0F, FontStyle.Bold);
To get installed fonts refer this - .NET System.Drawing.Font - Get Available Sizes and Styles
要获得已安装的字体,请参阅此 - .NET System.Drawing.Font - Get Available Sizes and Styles
回答by Abhinandan
Use this one to change only font size not the name of the font
使用这个只更改字体大小而不是字体名称
label1.Font = new System.Drawing.Font(label1.Font.Name, 24F);
回答by Ak?n I??k
You can also create a varible and then assign it for a text. It is cool because you can assign it two or more texts.
您还可以创建一个变量,然后将其分配给文本。这很酷,因为您可以为其分配两个或多个文本。
To assign a variable do that
分配一个变量这样做
public partial class Sayfa1 : Form
Font Normal = new Font("Segoe UI", 9, FontStyle.Bold);
public Sayfa1()
This varible is not assigned to any text yet.To do it write the name of the text(Look proporties -> (Name)) then write ".Font" then call the name of your font variable.
这个变量还没有分配给任何文本。要做到这一点,请写下文本的名称(Look proporties -> (Name)),然后写下“.Font”,然后调用您的字体变量的名称。
lupusToolStripMenuItem.Font = Normal;
Now you have a text assigned to a Normal font. I hope I could be helpful.
现在您已将文本分配给 Normal 字体。我希望我能有所帮助。

