|
-
February 18th, 2003, 04:09 AM
#1
Problem with a Sub's Argument
I have a Form with a number of Panels and each panel contains a large number of labels and pictureboxes.
When the user clicks on any label, I want the text forecolor of all the labels in that particular panel to change to another color .
I thought I could do it with this Sub, but it throws an error :-
Code:
Private Sub ChangePanelTextColor(ByRef PN As Panel)
Try
Dim l As Label
For Each l In PN.Controls
l.ForeColor = System.Drawing.Color.BurlyWood
Next
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
and I called it from a Label_Click event in the usual way
Code:
ChangePanelTextColor(<Name of Panel containing this Label>)
Have I missed something really obvious and basic here ? Or do I have to go about it in a completely different way?
JDP
-
February 18th, 2003, 07:27 AM
#2
Your problem happens when the panel also contains other controls then labels.
Then the For Each tries to fill 'l' with an different type of control then a label.
Try the following sub
Private Sub ChangePanelTextColor(ByRef PN As Panel)
Try
Dim l As Control
For Each l In PN.Controls
If l.GetType Is GetType(Label) Then
l.ForeColor = System.Drawing.Color.BurlyWood
End If
Next
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
-
February 18th, 2003, 02:41 PM
#3
Many thanks, Jan.
That did the trick!
JD
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
|