Reputation: 88189
How do I set the font of a TextBox
from a string
in the code behind?
// example
txtEditor.FontFamily = "Consolas";
Upvotes: 39
Views: 99075
Reputation: 1969
One simple way to do it globally, programmatically:
public MainWindow()
{
this.FontFamily = new FontFamily("Segoe UI");
}
Upvotes: 3
Reputation: 201
Use the following syntax:
lblCounting.Font = new Font("Times New Roman", 50);
Where lblCounting
is just any label.
Upvotes: 20
Reputation: 59101
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");
}
}
Upvotes: 3
Reputation: 136603
txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace
Upvotes: 61