I have a created windows application in VB.net. now I want apply style to it. Like I want apply background color, button style, font type etc from signal setting. And didn't want go and style style to Individual controls.
-
Can you tell us what you have already tried? – Dan Feb 23 '14 at 18:59
-
Then you might wanna look for custom-themes or something. – SomeNickName Feb 23 '14 at 19:30
1 Answers
There are several solutions:
You can store all form settings (the settings that should change for each theme) in
My.Settingsand then apply these settings to each form. Here's a tutorial that might help you.Example (in the
Loadevent handler):' ... Me.BackColor = My.Settings.ThemeBackColor ' ...If you have multiple themes that the user can choose from, then store them in separate settings files and read them into the program.
In order to apply settings to multiple controls, loop through all of them and apply the settings. See https://stackoverflow.com/a/4674181/2671135 for more information on how to get all controls of a certain type.
You could also create a
Modulewith aPublic Subsimilar to this:Public Module Theme Public Sub ApplyTheme(ByRef form As System.Windows.Forms.Form) With form .BackColor = Color.Black .Color = Color.Green ' ... End With End Sub End ModuleInside each form's
Loadevent handler, simply call this method:ApplyTheme(Me)Again, see https://stackoverflow.com/a/4674181/2671135 for more information on how to loop through form controls.
Another option would be to create a class that
Inherits System.Windows.Forms.Form. In the constructor method, set all settings as appropriate. Then, for each form, inherit from this class.
I faced the same problem a while ago and I created a DLL that automates the second solution. Check it out on GitHub, especially the ConfigureWindow method in this file. It is written in C#.NET though, but I hope it helps anyway...