【问题标题】:Easiest way to change font and font size更改字体和字体大小的最简单方法
【发布时间】:2012-04-27 17:24:18
【问题描述】:

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

在 java 中,这一切都可以通过调用带有必要参数的 Font 构造函数来轻松完成。

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

【问题讨论】:

    标签: c# winforms fonts


    【解决方案1】:

    可能是这样的:

    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

    【讨论】:

    • 很久没说话了——但你没有处理旧字体——如果你经常这样做——你可能会用完 GDI 句柄。我说的对吗?
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      使用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

      【讨论】:

        【解决方案4】:

        应该这样做(粗体);

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

        【讨论】:

          【解决方案5】:

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

          要分配一个变量这样做

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

          此变量尚未分配给任何文本。为此,请写入文本的名称(查看比例 ->(名称)),然后写入“.Font”,然后调用您的字体变量的名称。

          lupusToolStripMenuItem.Font = Normal;
          

          现在您有一个分配给普通字体的文本。我希望我能有所帮助。

          【讨论】:

            【解决方案6】:

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

            【讨论】:

              猜你喜欢
              • 2011-12-29
              • 2011-06-14
              • 1970-01-01
              • 2017-11-30
              • 2011-06-25
              • 2015-05-10
              • 2011-05-26
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多