Setting up font of TextBox from code behind

前端 未结 6 938
臣服心动
臣服心动 2021-02-05 00:49

How do I set the font of a TextBox from a string in the code behind?

// example
txtEditor.FontFamily = "Consolas";
         


        
6条回答
  •  故里飘歌
    2021-02-05 01:49

    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");
        }
    }
    

提交回复
热议问题