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. Labels and Mouse

Labels and Mouse

Scheduled Pinned Locked Moved Visual Basic
data-structuresquestion
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 have an array of labels on a form. I want to track which one was clicked on (right click). Anyone know an easy way to do this?

    R 1 Reply Last reply
    0
    • N No e

      I have an array of labels on a form. I want to track which one was clicked on (right click). Anyone know an easy way to do this?

      R Offline
      R Offline
      Richard_Wolf
      wrote on last edited by
      #2

      Since you're referencing an array of labels I assume you're not using .NET. In that case, the MouseDown event for the control array would probably be eaisest: Private Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then MsgBox "Label = " & Label1(Index).Caption & " Index = " & Index End If End Sub

      N 1 Reply Last reply
      0
      • R Richard_Wolf

        Since you're referencing an array of labels I assume you're not using .NET. In that case, the MouseDown event for the control array would probably be eaisest: Private Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then MsgBox "Label = " & Label1(Index).Caption & " Index = " & Index End If End Sub

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

        Thanks, but I am using .NET. It appears the compatability wizzard converted these, from the "VisualBasic.Compatability" class, guess I need to look at changing those as well. Any quick suggestions as to how to go about doing this progaramatically? I need to load a bunch of labels on screen (representing slots) and allow the operator to select individual ones. The number and orientation depend on the system configuration at the time and can not be hard coded.

        R 1 Reply Last reply
        0
        • N No e

          Thanks, but I am using .NET. It appears the compatability wizzard converted these, from the "VisualBasic.Compatability" class, guess I need to look at changing those as well. Any quick suggestions as to how to go about doing this progaramatically? I need to load a bunch of labels on screen (representing slots) and allow the operator to select individual ones. The number and orientation depend on the system configuration at the time and can not be hard coded.

          R Offline
          R Offline
          Richard_Wolf
          wrote on last edited by
          #4

          First off, the conversion wizard is the devil, just rewrite ;) The concept is very similar: Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown, Label2.MouseDown If e.Button = Windows.Forms.MouseButtons.Right Then MsgBox("Label = " & sender.Name) End If End Sub This assumes you have a static "maximum" number of labels that you can keep hidden unless needed and have all of them listed on the event handles. If you need a variable number of labels that you can't predefine then you will need to create a new label control, and assign it to the event handler. I will leave that example to someone a bit more familiar with .NET than myself.

          S 1 Reply Last reply
          0
          • R Richard_Wolf

            First off, the conversion wizard is the devil, just rewrite ;) The concept is very similar: Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown, Label2.MouseDown If e.Button = Windows.Forms.MouseButtons.Right Then MsgBox("Label = " & sender.Name) End If End Sub This assumes you have a static "maximum" number of labels that you can keep hidden unless needed and have all of them listed on the event handles. If you need a variable number of labels that you can't predefine then you will need to create a new label control, and assign it to the event handler. I will leave that example to someone a bit more familiar with .NET than myself.

            S Offline
            S Offline
            StylezHouse
            wrote on last edited by
            #5

            First off, the conversion wizard is the devil, just rewrite

            Agreed, once you have the fundamentals down, I'd suggest a complete rewrite as well.

            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