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

时间:2012-04-16 11:21:29

标签: c# winforms fonts

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

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

JLabel lab  = new JLabel("Font Bold at 24");
lab.setFont(new Font("Serif", Font.BOLD, 24));

6 个答案:

答案 0 :(得分:79)

也许是这样的:

yourformName.YourLabel.Font = new Font("Arial", 24,FontStyle.Bold);

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

YourLabel.Font = new Font("Arial", 24,FontStyle.Bold);

构造函数采用不同的参数(所以选择你的毒药)。像这样:

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)

参考here

答案 1 :(得分:8)

使用Font Class设置控件的字体和样式。

尝试Font Constructor (String, Single)

Label lab  = new Label();
lab.Text ="Font Bold at 24";
lab.Font = new Font("Arial", 20);

lab.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold);

要获取已安装的字体,请参阅此处 - .NET System.Drawing.Font - Get Available Sizes and Styles

答案 2 :(得分:5)

这应该做(粗体);

label1.Font = new Font("Serif", 24,FontStyle.Bold);

答案 3 :(得分:2)

您还可以创建变量,然后为文本指定它。这很酷,因为你可以为它分配两个或多个文本。

分配变量

public partial class Sayfa1 : Form

   Font Normal = new Font("Segoe UI", 9, FontStyle.Bold);

    public Sayfa1()

此变量尚未分配给任何文本。要写入文本名称(Look proportion - >(Name)),然后写“.Font”,然后调用字体变量的名称。

lupusToolStripMenuItem.Font = Normal;

现在您有一个分配给Normal字体的文本。我希望我能提供帮助。

答案 4 :(得分:0)

您可以使用属性面板中的label属性来更改它。 This screen shot is example that

答案 5 :(得分:-1)

float currentSize; currentSize = richTextbox1.Font.Size; currentSize = 8;

这是Visual Studio C#的100%工作。