Reputation: 77
I apologize if this question is listed elsewhere and I just didn't find it in my search. I am trying to find a way to set the DefaultFont property of a form so that users can select the font they want and it will be auto set every time the form opens. I already have the code to save to the user settings, I'm just looking for a way to set the Default Font property. I'm using Visual Studio 2005 with C#. Please let me know if there isn't enough info in here. Thanks!
Upvotes: 4
Views: 5240
Reputation: 180888
I think you have to enumerate the controls collection and set the font for each control on the form individually.
But as Henk points out, if your controls have no font settings in the designer, they will inherit the font settings for the form.
Upvotes: 2
Reputation: 23759
The Control.DefaultFont property returns the default font for this control that is set in the system. You cannot change this property as it is read-only.
Maybe you just want to set the Control.Font property of the form. You could use a second constructor that takes the font object as parameter and sets it before InitializeComponent is called.
Upvotes: 1
Reputation: 273691
Basically, it is
private void Form1_Load(object sender, EventArgs e)
{
this.Font = font_from_settings;
}
But it will be a little tricky to make sure no control is overriding it's own font property. You can use the designer to reset font-properties or delete them from *.Designer.cs
Upvotes: 6