[b][red]This message was edited by Tsikman at 2003-5-10 19:55:35[/red][/b][hr]
[b][red]This message was edited by Tsikman at 2003-5-10 19:53:47[/red][/b][hr]
Basically, I need a toggle switch for 26 labels. When one of them is clicked, that particular label changes color and back if the label is clicked again. making 26 click routines seems like a ridiculous waste of time. As you ccan probably tell I am new to programing
here is the long way
(dim temp as integer = 1)
Private Sub lblA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblA.Click
If temp = 1 Then
lblA.ForeColor = Drawing.Color.Red
temp = 2
ElseIf temp = 2 Then
lblA.ForeColor = Drawing.Color.Black
temp = 1
End If
End Sub
Private Sub lblB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblB.Click
If temp = 1 Then
lblA.ForeColor = Drawing.Color.Red
temp = 2
ElseIf temp = 2 Then
lblA.ForeColor = Drawing.Color.Black
temp = 1
End If
End Sub
Private Sub lblC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblC.Click
If temp = 1 Then
lblA.ForeColor = Drawing.Color.Red
temp = 2
ElseIf temp = 2 Then
lblA.ForeColor = Drawing.Color.Black
temp = 1
End If
End Sub
Private Sub lblD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblD.Click
If temp = 1 Then
lblA.ForeColor = Drawing.Color.Red
temp = 2
ElseIf temp = 2 Then
lblA.ForeColor = Drawing.Color.Black
temp = 1
End If
End Suby
Comments
: [b][red]This message was edited by Tsikman at 2003-5-10 19:53:47[/red][/b][hr]
: Basically, I need a toggle switch for 26 labels. When one of them is clicked, that particular label changes color and back if the label is clicked again. making 26 click routines seems like a ridiculous waste of time. As you ccan probably tell I am new to programing
:
: here is the long way
:
: (dim temp as integer = 1)
: Private Sub lblA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblA.Click
: If temp = 1 Then
: lblA.ForeColor = Drawing.Color.Red
: temp = 2
: ElseIf temp = 2 Then
: lblA.ForeColor = Drawing.Color.Black
: temp = 1
: End If
: End Sub
:
: Private Sub lblB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblB.Click
: If temp = 1 Then
: lblA.ForeColor = Drawing.Color.Red
: temp = 2
: ElseIf temp = 2 Then
: lblA.ForeColor = Drawing.Color.Black
: temp = 1
: End If
: End Sub
:
: Private Sub lblC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblC.Click
: If temp = 1 Then
: lblA.ForeColor = Drawing.Color.Red
: temp = 2
: ElseIf temp = 2 Then
: lblA.ForeColor = Drawing.Color.Black
: temp = 1
: End If
: End Sub
:
: Private Sub lblD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblD.Click
: If temp = 1 Then
: lblA.ForeColor = Drawing.Color.Red
: temp = 2
: ElseIf temp = 2 Then
: lblA.ForeColor = Drawing.Color.Black
: temp = 1
: End If
: End Suby
:
:
:
:
: Hi Tsikman
Basically all you need to do is to create a sub routine and pass a label as an argument:
Dim temp as integer = 1
Private Sub lblA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblA.Click
Dim MyLabel as lblA
Call ChooseLabel(ByVal MyLabel as label)
End Sub
Private ChooseLabel(ByVal MyLabel as label)
: If temp = 1 Then
: MyLabel.ForeColor = Drawing.Color.Red
: temp = 2
: ElseIf temp = 2 Then
: MyLabel.ForeColor = Drawing.Color.Black
: temp = 1
: End If
: End Sub
:
Private Sub lblB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblA.Click
Dim MyLabel as lblB
Call ChooseLabel(ByVal MyLabel as label)
End Sub
I really don't want to create all the click routines./=
Now in your event handler you can write code like this:
[code]
Private Sub lblD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblA.Click, lblB.Click, lblC.Click 'etc
' sender is the target label
dim Label lbl as Label = CType(sender, Label)
If temp = 1 Then
lbl.ForeColor = Drawing.Color.Red
temp = 2
ElseIf temp = 2 Then
lbl.ForeColor = Drawing.Color.Black
temp = 1
End If
End Sub
[/code]