Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Context Menu

Context Menu

Scheduled Pinned Locked Moved Visual Basic
questiongraphicsdata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    No e
    wrote on last edited by
    #1

    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 Sub

    I 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 Sub

    All 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

    J B 2 Replies Last reply
    0
    • N 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 Sub

      I 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 Sub

      All 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

      J Offline
      J Offline
      Jon_Boy
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • J Jon_Boy

        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

        N Offline
        N Offline
        No e
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • N No e

          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.

          J Offline
          J Offline
          Jon_Boy
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • N 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 Sub

            I 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 Sub

            All 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

            B Offline
            B Offline
            Bahram Zarrin
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups