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:
  1. Private Sub setTheme(ByRef frmObj as Form)
  2.         For i As Integer = 0 To frmObj.Controls.Count - 1
  3.             If frmObj.Controls.Item(i).Controls.Count <> 0 Then
  4.                 For ind As Integer = 0 To frmObj.Controls.Item(i).Controls.Count - 1
  5.                     frmObj.Controls.Item(i).Controls.Item(ind).ForeColor() = Color.FromName(themeForeColour)
  6.                     frmObj.Controls.Item(i).Controls.Item(ind).BackColor() = Color.FromName(themeBackColour)
  7.                 Next
  8.             End If
  9.             frmObj.ForeColor() = Color.FromName(themeForeColour)
  10.             frmObj.BackColor() = Color.FromName(themeBackColour)
  11.             frmObj.Opacity = themeOpacity
  12.             frmObj.Controls.Item(i).ForeColor = Color.FromName(themeForeColour)
  13.             frmObj.Controls.Item(i).BackColor = Color.FromName(themeBackColour)
  14.             If TypeOf frmObj.Controls.Item(i) Is Button Then
  15.                 Dim thisButton As Button = frmObj.Controls.Item(i)
  16.                 Select Case themeFlatStyle.ToLower
  17.                     Case "flat"
  18.                         thisButton.FlatStyle = 0
  19.                     Case "popup"
  20.                         thisButton.FlatStyle = 1
  21.                     Case "standard"
  22.                         thisButton.FlatStyle = 2
  23.                     Case Else
  24.                         thisButton.FlatStyle = 3
  25.                 End Select
  26.             End If
  27.         Next i
  28. 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.