Context Menu
-
I created a control array (for slots)
Private Sub createlblSlotArray()
Dim i As Short
ReDim lblSlot(3)
For i = 1 To 3
lblSlot(i) = New System.Windows.Forms.Label
With lblSlot(i)
.Tag = i
.BackColor = System.Drawing.Color.Blue
.BorderStyle = BorderStyle.Fixed3D
AddHandler .MouseUp, AddressOf Me.Label1_MouseUp
End With
Next
Me.Controls.AddRange(lblSlot)
lblSlot(1).Location = New System.Drawing.Point(50, 50)
lblSlot(2).Location = New System.Drawing.Point(100, 70)
lblSlot(3).Location = New System.Drawing.Point(100, 90)
End SubI have an event to handle it
Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(sender, New Point(e.X, e.Y))
End If
End SubAll is perfect with the world, except one little thing. When I click on the form itself, I get the popup. Why do I get it on the form, how can I prevent this? No-e
-
I created a control array (for slots)
Private Sub createlblSlotArray()
Dim i As Short
ReDim lblSlot(3)
For i = 1 To 3
lblSlot(i) = New System.Windows.Forms.Label
With lblSlot(i)
.Tag = i
.BackColor = System.Drawing.Color.Blue
.BorderStyle = BorderStyle.Fixed3D
AddHandler .MouseUp, AddressOf Me.Label1_MouseUp
End With
Next
Me.Controls.AddRange(lblSlot)
lblSlot(1).Location = New System.Drawing.Point(50, 50)
lblSlot(2).Location = New System.Drawing.Point(100, 70)
lblSlot(3).Location = New System.Drawing.Point(100, 90)
End SubI have an event to handle it
Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(sender, New Point(e.X, e.Y))
End If
End SubAll is perfect with the world, except one little thing. When I click on the form itself, I get the popup. Why do I get it on the form, how can I prevent this? No-e
Dunno, I copied your code into a test project and the ContextMenu is displayed when right clicking on the labels (I had to DirectCast(sender, Control) though). The menu is not displayed when clicking on the form. There isn't a need to create a new question everytime for something you've already asked. You could have replied on your previous question since it is the same.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
Dunno, I copied your code into a test project and the ContextMenu is displayed when right clicking on the labels (I had to DirectCast(sender, Control) though). The menu is not displayed when clicking on the form. There isn't a need to create a new question everytime for something you've already asked. You could have replied on your previous question since it is the same.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
huh? Same question? Things change from vb6 to .net. I am trying to understand how things work. I tend to be a quick learner, but am just asking for help or a tip where to look when I do not understand something. This project was dropped in my lap and I have many other things to deal with. last Q was why my mouse position was in an unexpected location. Thanks to Henry Minute, it saved me some time, perfect! that is all I ask, point me in a direction should I not bother here? Am I asking unfair questions? Should I go away? No-e BTW, I found a way to address the problem. no thanks to your response. I am disappointed with your response, I thought CP members were a little more considerate. I am not a student asking you to do my homework.
-
huh? Same question? Things change from vb6 to .net. I am trying to understand how things work. I tend to be a quick learner, but am just asking for help or a tip where to look when I do not understand something. This project was dropped in my lap and I have many other things to deal with. last Q was why my mouse position was in an unexpected location. Thanks to Henry Minute, it saved me some time, perfect! that is all I ask, point me in a direction should I not bother here? Am I asking unfair questions? Should I go away? No-e BTW, I found a way to address the problem. no thanks to your response. I am disappointed with your response, I thought CP members were a little more considerate. I am not a student asking you to do my homework.
Hmm, I recall a previous post related to a context menu and where it appeared the day before (and was appearing unexpectedly). Dunno, kinda seemed related to me. Regardless, I'm sorry that I took time out of my day to create a test project with your code to find a possible error. No need to apologize. I'll restrain from replying to any of your future posts. Cheers!
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
I created a control array (for slots)
Private Sub createlblSlotArray()
Dim i As Short
ReDim lblSlot(3)
For i = 1 To 3
lblSlot(i) = New System.Windows.Forms.Label
With lblSlot(i)
.Tag = i
.BackColor = System.Drawing.Color.Blue
.BorderStyle = BorderStyle.Fixed3D
AddHandler .MouseUp, AddressOf Me.Label1_MouseUp
End With
Next
Me.Controls.AddRange(lblSlot)
lblSlot(1).Location = New System.Drawing.Point(50, 50)
lblSlot(2).Location = New System.Drawing.Point(100, 70)
lblSlot(3).Location = New System.Drawing.Point(100, 90)
End SubI have an event to handle it
Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(sender, New Point(e.X, e.Y))
End If
End SubAll is perfect with the world, except one little thing. When I click on the form itself, I get the popup. Why do I get it on the form, how can I prevent this? No-e
I think it's better write this code: Private Sub createlblSlotArray() Dim i As Short ReDim lblSlot(3) For i = 1 To 3 lblSlot(i) = New System.Windows.Forms.Label With lblSlot(i) .Tag = i .BackColor = System.Drawing.Color.Blue .BorderStyle = BorderStyle.Fixed3D .ContextMenu=ContexMenu1 End With Next Me.Controls.AddRange(lblSlot) lblSlot(1).Location = New System.Drawing.Point(50, 50) lblSlot(2).Location = New System.Drawing.Point(100, 70) lblSlot(3).Location = New System.Drawing.Point(100, 90) End Sub bah10z