Setting up font of TextBox from code behind

前端 未结 6 919
臣服心动
臣服心动 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:25
    txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace
    
    0 讨论(0)
  • 2021-02-05 01:36

    One simple way to do it globally, programmatically:

    public MainWindow()
    {
        this.FontFamily = new FontFamily("Segoe UI");
    }
    
    0 讨论(0)
  • 2021-02-05 01:40

    Use the following syntax:

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

    Where lblCounting is just any label.

    0 讨论(0)
  • 2021-02-05 01:41

    Use txtEditor.Font.Name = "Consolas";

    0 讨论(0)
  • 2021-02-05 01:47
    System.Drawing.Font = new Font("Arial", 8, FontStyle.Bold);
    
    0 讨论(0)
  • 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");
        }
    }
    
    0 讨论(0)
提交回复
热议问题