Setting Font of TextBox from code behind

本小妞迷上赌 提交于 2019-12-03 10:32:03

问题


This maybe a stupid question but how do I set the font of a TextBox from a string in the code behind?

// example
txtEditor.FontFamily = "Consolas";

回答1:


txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace



回答2:


Use the following syntax:

lblCounting.Font  = new Font("Times New Roman", 50);

Where lblCounting is just any label.




回答3:


System.Drawing.Font = new Font("Arial", 8, FontStyle.Bold);



回答4:


One simple way to do it globally, programmatically:

public MainWindow()
{
    this.FontFamily = new FontFamily("Segoe UI");
}



回答5:


Copy and paste your example code into the constructor of the form, right after InitializeComponent();

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        txtEditor.FontFamily = new FontFamily("Consolas");
    }
}



回答6:


Use txtEditor.Font.Name = "Consolas";



来源:https://stackoverflow.com/questions/4002290/setting-font-of-textbox-from-code-behind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!