J
jcrouse
I have a test app with one button and a context menu. When I click on the
button, it adds a label with some properties, one being the assignment of
the context menu. If I add 5 buttons then want to delete one I can right
click and choose Delete from the context menu. The problems is that I don't
know the proper verbage to search for (in help) to find the code to tell
which label is the one the received the right click event. I'm not sure if
sender is the proper word but I need to know which label is the sender.
Also, how will I the reference the individual labels is code? What will
their names be (or how can I assign a unique name to each label)? I don't
really want to use a loop because I may add a couple of labels then later
add a couple of more and so on (or possibly delete some). I hope this makes
sense. Here is my code.
Dim intTopCounter As Integer = 20
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim MyLabel As New Label
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Top = intTopCounter
MyLabel.Left = 40
MyLabel.ContextMenu = cmnuLabels
intTopCounter = intTopCounter + 30
Me.Controls.Add(MyLabel)
End Sub
Private Sub cmDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmDelete.Click
'Delete Label Code Here
End Sub
Thanks,
John
button, it adds a label with some properties, one being the assignment of
the context menu. If I add 5 buttons then want to delete one I can right
click and choose Delete from the context menu. The problems is that I don't
know the proper verbage to search for (in help) to find the code to tell
which label is the one the received the right click event. I'm not sure if
sender is the proper word but I need to know which label is the sender.
Also, how will I the reference the individual labels is code? What will
their names be (or how can I assign a unique name to each label)? I don't
really want to use a loop because I may add a couple of labels then later
add a couple of more and so on (or possibly delete some). I hope this makes
sense. Here is my code.
Dim intTopCounter As Integer = 20
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim MyLabel As New Label
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Top = intTopCounter
MyLabel.Left = 40
MyLabel.ContextMenu = cmnuLabels
intTopCounter = intTopCounter + 30
Me.Controls.Add(MyLabel)
End Sub
Private Sub cmDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmDelete.Click
'Delete Label Code Here
End Sub
Thanks,
John