c#设置TextBox的FontSize

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13529563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:55:29  来源:igfitidea点击:

c# set FontSize of TextBox

c#textboxfont-size

提问by Jordan Trainor

How would I set the font size of a TextBox in c#. I can get the current size but it does not allow to set it.

我将如何在 c# 中设置 TextBox 的字体大小。我可以获得当前大小,但不允许设置它。

public static Form client;
((TextBox)client.Controls[0]).Font.size = 16;

采纳答案by Jon B

You have to set the Fontproperty. Sizeis a readonly property of Font.

您必须设置该Font属性。Size是 的只读属性Font

var textBox = (TextBox)client.Controls[0];
textBox.Font = new Font(textBox.Font.FontFamily, 16);