0

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.

1 Answers1

3

There are several solutions:

  1. You can store all form settings (the settings that should change for each theme) in My.Settings and then apply these settings to each form. Here's a tutorial that might help you.

    Example (in the Load event 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.

  2. You could also create a Module with a Public Sub similar 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 Module
    

    Inside each form's Load event 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.

  3. 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...

Community
  • 1
  • 1
Georg
  • 378
  • 1
  • 3
  • 10