tags:

views:

20

answers:

3

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  A: 
txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace
Gishu
A: 

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");
    }
}
Merlyn Morgan-Graham
A: 

Use txtEditor.Font.Name = "Consolas";

Rahul Soni