How do I set the font of a TextBox
from a string
in the code behind?
// example
txtEditor.FontFamily = "Consolas";
How do I set the font of a TextBox
from a string
in the code behind?
// example
txtEditor.FontFamily = "Consolas";
txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace
txtEditor
is a System.Windows.Forms.TextBox, there is no FontFamily property on that object, but there is a Font property. –
Min Use the following syntax:
lblCounting.Font = new Font("Times New Roman", 50);
Where lblCounting
is just any label.
lblCounting.Font = new Font("Times New Roman", 50);
–
Smell System.Drawing.Font = new Font("Arial", 8, FontStyle.Bold);
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");
}
}
One simple way to do it globally, programmatically:
public MainWindow()
{
this.FontFamily = new FontFamily("Segoe UI");
}
© 2022 - 2024 — McMap. All rights reserved.