简体   繁体   English

如何在C#中设置Textbox.Font.Size?

[英]How to set Textbox.Font.Size in C#?

我将font.size加载到此格式为字符串的文件中,并且我想通过此值设置textbox.font.size,但要说“未设置此值为只读”,我如何在编码中设置font.size?

By Using this it is possible to programmatically choose the best font. 通过使用此功能,可以以编程方式选择最佳字体。 This also allows you to set different sizes on the various alternative fonts. 这还允许您在各种备用字体上设置不同的大小。

Font font = new Font("Times New Roman", 16.0f, 
                        FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
textBox1.Font = font;

For more details, check here 欲了解更多详情,请点击这里

You can Set the Font Property of TextBox Control. 您可以设置TextBox控件的Font属性。

Font Property of TextBox Control Expects Font Class Object. TextBox控件的Font属性需要Font类对象。

you can create the Font class oject with different styles by passing different parameters to its constructors. 您可以通过将不同的参数传递给其构造函数来创建具有不同样式的Font类对象。

Font Class Constructor Description : 字体类构造函数说明:

FontFamily - FontFamily (EnumType) : used to specify Font name ex:Arial,Times New Roman etc., FontFamily-FontFamily(EnumType):用于指定字体名称,例如:Arial,Times New Roman等,

FontSize - float(DataType) : it's a float value of font size. FontSize-float(DataType):它是字体大小的float值。

FontStyle - FontStyle (EnumType) : it is a FontStyle of different types ex: FontStyle.Regular,FontStyle.Bold,FontStyle.Italic etc., FontStyle-FontStyle(EnumType):它是不同类型的FontStyle,例如:FontStyle.Regular,FontStyle.Bold,FontStyle.Italic等,

Now See sample Example: 现在查看示例示例:

Font fnt=new Font(textBox1.Font.FontFamily,12.0F);//Edit your size asper your requirement. it's float value
        textBox1.Font = fnt;

从当前字体创建新字体(将其用作原型)并提供字体大小(将字符串解析为浮动):

 textBox1.Font = new Font(textBox1.Font, Single.Parse(sizeString));

You have to set it at start of the Initialization of textbox 您必须在文本框初始化开始时进行设置

like 喜欢

var textbox = new TextBox()
                  {
                     FontFamily = "Segoe WP",
                     FontSize = 18
                  };

Font.Size is read only. Font.Size是只读的。 You must set the Font object itself. 您必须设置Font对象本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM