VB.NET - Provide predefined creation settings in a class
I'm writing a theming class called FormTheme for a VB.NET form application. It contains colour scheme information that can be applied at runtime to form controls. Currently there are three ways to instantiate an object:
Public Sub New()
Creates a new theme with the default system colours.
Public Sub New(ByVal ForeColor As Color, _ ByVal BackColor As Color, _ ByVal BorderColor As Color ... )
Creates a new theme with the provided colours.
Public Sub New(ByRef ExistingTheme As FormTheme)
Creates a new theme by doing a 'deep copy' of an existing theme.
I would like to provide a fourth option to create a theme based on pre-defined settings, for example:
Public Sub New(ByVal scheme As ColorScheme) 'usage: Dim myTheme As New FormTheme(ColorScheme.Night)
Was wondering what would be the best way to implement this? Considered using an Enum and a Select Case statement in the constructor to theme based on the enum value, which would certainly work:
Enum ColorScheme Day Night City Candy ... End Enum Public Sub New(ByVal scheme as ColorScheme) Select scheme Case ColorScheme.Day 'Set colors Case ColorScheme.Night 'Set colors Case ColorScheme.City 'Set colors ... End Select End Sub
Before I forge ahead, is there a more standard or 'better' way of doing this?
Looks like a good ways of doing it.
You could always preload all the colorsccheme in a dictionnary
Dim colorSchemeList As Dictionnary(Of ColorScheme, FormTheme)
Loaded in a static constructor and them your New would look something like
Public Sub New(ByVal scheme as ColorScheme) New(colorSchemeList(scheme)) End Sub