i got 59 labels (they describe places in a storage system). With a context menu i want to lock or unlock each of those places for the user. So in my contextmenu i got two items: Lock and Unlock. If one label (place) is locked by the user it should send an bit to a plc (but that is not my main problem), and the same for unlock.
Is there any opportunity to do a loop, to find out on which label the contextmenu has been opened? (MouseDown Event)
Here my code so far:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.ContextMenuStrip = ContextMenuStrip1
End Sub
Private Sub Label1_MouseDown(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown, Label2.MouseDown, Label3.MouseDown, Label4.MouseDown, .............. , Label59.MouseDown
ContextMenuStrip1.Tag = sender
End Sub
Private Sub LockToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LockToolStripMenuItem.Click
'send bit to PLC (sender)
End Sub
Private Sub UnlockToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UnlockToolStripMenuItem.Click
'send bit to PLC (sender)
End Sub
End Class
Sorry for the bad english.
fruitContextMenuStrip.Items.Add("Source: " + c.GetType().ToString());
and as i tried it, it said "Source: System.Windows.Forms.Label". So the SourceControl command can#t be transferred to string with the number of the label? – HappyHippo73 Jul 09 '21 at 12:46