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

本文关键字:字体 最简单 方法 | 更新日期: 2023-09-27 18:31:19

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

使用

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

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

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

也许是这样的:

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)

参考这里

使用这个只更改字体大小而不是字体名称

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

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

试用字体构造函数(字符串、单个)

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 - 获取可用的大小和样式

这应该可以做到(粗体);

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

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

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

public partial class Sayfa1 : Form
   Font Normal = new Font("Segoe UI", 9, FontStyle.Bold);
    public Sayfa1()

此变量尚未分配给任何文本。为此,请写下文本的名称(查看 proporties ->(名称)),然后写".字体",然后调用字体变量的名称。

lupusToolStripMenuItem.Font = Normal;

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

您可以使用

属性面板中的标签属性进行更改。此屏幕截图是以下示例