-
Aug 11th, 2005, 10:26 AM
#1
Thread Starter
New Member
How to check if a property exists in a control.
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.
-
Aug 11th, 2005, 07:50 PM
#2
Thread Starter
New Member
Re: How to check if a property exists in a control.
In case anyone is trying to use the above code and hitting problems with the "opacity" property (doubt it...but just in case) themeOpacity is set, elsewhere, by me as
Code:
themeOpacity = Double.Parse(themeOpacity / 100)
since I allow the user to scroll the opacity from 25 to 100.
-
Aug 11th, 2005, 08:03 PM
#3
Re: How to check if a property exists in a control.
VB Code:
For Each ctl As Control In Me.Controls
If ctl.GetType().GetProperty("FlatStyle") Is Nothing Then
MessageBox.Show(ctl.Name & " does not have a FlatStyle property.")
Else
MessageBox.Show(ctl.Name & " has a FlatStyle property.")
End If
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|