最简单的更改字体和字号的方法

76

什么是使用C#改变字体大小的最简单方法。

使用Java可以通过调用带有必要参数的Font构造函数轻松完成所有操作。

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

126
也许可以这样做:
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)

请参考这里


好久不见了 - 但你没有处理旧字体 - 如果你这样做很多次 - 你可能会用完GDI句柄。我说得对吗? - ephraim

34

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

label1.Font = new System.Drawing.Font(label1.Font.Name, 24F);

12

7
这应该可以解决问题(同时也加粗);
label1.Font = new Font("Serif", 24,FontStyle.Bold);

4

您还可以创建一个变量,然后将其分配给文本。这很酷,因为您可以将其分配给两个或更多的文本。

要分配变量,请执行以下操作

public partial class Sayfa1 : Form

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

    public Sayfa1()

这个变量还没有分配给任何文本。要做到这一点,写出文本的名称(查看属性->(名称)),然后写上“.Font”,接着调用你的字体变量的名称。

lupusToolStripMenuItem.Font = Normal;

现在您已经将文本分配给了普通字体。我希望这能对您有所帮助。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接