Results 1 to 4 of 4

Thread: Mouse Buttons and Labels

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Ontario, Canada (near Buffalo, NY)
    Posts
    52

    Mouse Buttons and Labels

    I have a two dimensional array of labels with a common click event handler.

    I have not yet discovered the magic required to determine which mouse button was clicked in the handler. There is no lblArray(I,J).Buttons property.

    So my question is: How do I determine if th eright mouse button was clicked? I have tried:

    VB Code:
    1. if  lblArray(I, J).MouseButtons and MouseButtons.Right <> 0 then
    2. ...
    3. end if

    to no avail. In fact, lblArray(I,J).MouseButtons is always zero.

    (I have a way to determine the I and J from the mouse click.)

    RussCanada
    Ontario, Canada

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Mouse Buttons and Labels

    if you are handling the mouse clicks in the mousedown (or mousemove ??) event then the button state is available in e.button
    i.e.

    VB Code:
    1. Private Sub TitleBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TitleBar.MouseDown
    2.         If e.Button = MouseButtons.Right Then
    3.  
    4.         End If
    5.     End Sub
    HTH
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Ontario, Canada (near Buffalo, NY)
    Posts
    52

    Re: Mouse Buttons and Labels

    Kevin, I tried your suggestion but couldn't get it to work. I was not able to set up the proper handler for the MouseDown event. In your case, you knew the specific design-time object from which the event occurs, but in my situation I don't know until run-time. I presume there is something I don't know. (What else is new???)

    RussCanada
    Ontario

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Mouse Buttons and Labels

    The Control.MouseButtons property is Shared so you shouldn't be calling it on an instance anyway. It indicates which mouse buttons are depressed at that moment. To raise a Click event you must depress and release a mouse button so no buttons will be depressed when the Click event is raised.

    You should create your MouseDown and/or Click event handlers but omit the Handles clause. Once you've created your array of Labels you can use nested For loops to traverse the entire matrix and use the AddHandler statement to attach the event handlers to the appropriate events.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width