I am working on a "theme" system for my app(basic...just change back/fore colours, etc...) and would like to offer the ability to change the FlatStyle. However I hit a build error when iterating through the controls since FlatStyle isn't available to all controls. I was able to use "typeof" = "button" to add the FlatStyle to the buttons but I would rather just check if the property "FlatStyle" was available to the control instead.
VB Code:
Private Sub setTheme(ByRef frmObj as Form) For i As Integer = 0 To frmObj.Controls.Count - 1 If frmObj.Controls.Item(i).Controls.Count <> 0 Then For ind As Integer = 0 To frmObj.Controls.Item(i).Controls.Count - 1 frmObj.Controls.Item(i).Controls.Item(ind).ForeColor() = Color.FromName(themeForeColour) frmObj.Controls.Item(i).Controls.Item(ind).BackColor() = Color.FromName(themeBackColour) Next End If frmObj.ForeColor() = Color.FromName(themeForeColour) frmObj.BackColor() = Color.FromName(themeBackColour) frmObj.Opacity = themeOpacity frmObj.Controls.Item(i).ForeColor = Color.FromName(themeForeColour) frmObj.Controls.Item(i).BackColor = Color.FromName(themeBackColour) If TypeOf frmObj.Controls.Item(i) Is Button Then Dim thisButton As Button = frmObj.Controls.Item(i) Select Case themeFlatStyle.ToLower Case "flat" thisButton.FlatStyle = 0 Case "popup" thisButton.FlatStyle = 1 Case "standard" thisButton.FlatStyle = 2 Case Else thisButton.FlatStyle = 3 End Select End If Next i End Sub
The variables prefixed with "theme" above are 'global' variables that are loaded when the app starts or the theme is changed by the user on an options page.
Hopefully you will be able to help....or give me a better way to implement "themes". Thanks.




Reply With Quote