【发布时间】:2011-04-29 11:21:27
【问题描述】:
如何在后面的代码中从string 设置TextBox 的字体?
// example
txtEditor.FontFamily = "Consolas";
【问题讨论】:
-
不是一个愚蠢的问题。
标签: c# wpf code-behind
如何在后面的代码中从string 设置TextBox 的字体?
// example
txtEditor.FontFamily = "Consolas";
【问题讨论】:
标签: c# wpf code-behind
txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace
【讨论】:
txtEditor 是System.Windows.Forms.TextBox,则该对象没有FontFamily 属性,但有Font 属性。
使用以下语法:
lblCounting.Font = new Font("Times New Roman", 50);
lblCounting 是任何标签。
【讨论】:
lblCounting.Font = new Font("Times New Roman", 50);
System.Drawing.Font = new Font("Arial", 8, FontStyle.Bold);
【讨论】:
将您的示例代码复制并粘贴到表单的构造函数中,紧跟在InitializeComponent(); 之后
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
txtEditor.FontFamily = new FontFamily("Consolas");
}
}
【讨论】:
一种以编程方式在全局范围内执行此操作的简单方法:
public MainWindow()
{
this.FontFamily = new FontFamily("Segoe UI");
}
【讨论】:
使用 txtEditor.Font.Name = "Consolas";
【讨论】: