Sorry, forgot to say in the topic title that this is C#.
Let me explain what I want to do...
We all know that with Windows Vista brought a new UI font, Segoe UI, but XP still uses Tahoma as UI font. This doesn't help us programmers. I've searched in Google and what I found was to use SystemFonts.MessageBoxFont as the Form's font because all other controls Font properties will inherit from it.
Now, I could do this.font = SystemFonts.MessageBoxFont; before InitializeComponent(); on every single form I use but that will have 2 problems:
1) I'll have to repeat this line for every form.
2) The designer will not be updated accordingly.
If I moved this.font = SystemFonts.MessageBoxFont; into InitializeComponent() itself, then, the designer would be updated but I still would need to do it manually for every form.
My first solution:
Create a class (MyForm, for instance) that inherits from Form and change the properties I need in it's constructor. Then, every form I use in my application must be inherited from MyForm instead of Form. This is simpler than to place the line above in every InitializeComponent(), although, I still have to manually change every from to inherit from MyForm instead of Form.
To sum this up... I'm looking for a way (if possible) to change some default properties of Form without creating a new class that inherits from it, which allows me to make all the needed properties changes in one place and all my forms will still inherit from Form (as they are by default).
I can’t stand Musk, but he did not design it any more than he engineers Space X rockets. Stop helping give the clown credit for things he wants people to believe he did when in fact, he did not.
https://en.wikipedia.org/wiki/Franz_von_Holzhausen
Question
ProclaimDragon
Sorry, forgot to say in the topic title that this is C#.
Let me explain what I want to do...
We all know that with Windows Vista brought a new UI font, Segoe UI, but XP still uses Tahoma as UI font. This doesn't help us programmers. I've searched in Google and what I found was to use SystemFonts.MessageBoxFont as the Form's font because all other controls Font properties will inherit from it.
Now, I could do this.font = SystemFonts.MessageBoxFont; before InitializeComponent(); on every single form I use but that will have 2 problems:
1) I'll have to repeat this line for every form.
2) The designer will not be updated accordingly.
If I moved this.font = SystemFonts.MessageBoxFont; into InitializeComponent() itself, then, the designer would be updated but I still would need to do it manually for every form.
My first solution:
Create a class (MyForm, for instance) that inherits from Form and change the properties I need in it's constructor. Then, every form I use in my application must be inherited from MyForm instead of Form. This is simpler than to place the line above in every InitializeComponent(), although, I still have to manually change every from to inherit from MyForm instead of Form.
To sum this up... I'm looking for a way (if possible) to change some default properties of Form without creating a new class that inherits from it, which allows me to make all the needed properties changes in one place and all my forms will still inherit from Form (as they are by default).
Is this possible?
Edited by NazgulledLink to comment
https://www.neowin.net/forum/topic/638927-c-is-it-possible-to-override-the-form-class/Share on other sites
15 answers to this question
Recommended Posts