Results 1 to 11 of 11

Thread: [RESOLVED] [VS2005/CE] How to determine is mouse click was on a label

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] [VS2005/CE] How to determine is mouse click was on a label

    I'm believe that labels cannot receive click events - right?

    How would I determine if a mouse-click on a form (when checked in the FORM click event - I guess) was over a specific label?
    Last edited by szlamany; Apr 2nd, 2007 at 10:11 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    Re: How to determine is mouse click was on a label

    I'm not sure what version of .NET your using but 2003 has a click event for a label.
    VB Code:
    1. Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
    2. '...Enter your code
    3. End Sub

    Helpful Links:
    VB 6 - How to get the "Key" Value in a collection
    VB.NET - File Search Utility || VB.NET - How to compare 2 directories || VB.NET - How to trust a network share
    VB.NET - Create Excel Spreadsheet From Array || VB.NET - Example Code & Hints you may not know
    VB.NET - Save JPEG with a certain quality (image compression) || VB.NET - DragDrop Files, Emails, and Email Attachments

    Please post some of the code you need help with (it makes it easier to help you)
    If your problem has been solved then please mark the thread [RESOLVED].
    Don't forget to Rate this post

    "Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-

  3. #3
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Re: How to determine is mouse click was on a label

    They sure can, when you are in the form designer look to the top of the properties box, (not sure if that is the correct term but you know, the place where you type the name and the text of the label) There is little icon that looks like a lighting bolt. click that you will see all the events you can associate things with. There all all kinds of choices from hover to click.

    Hopefully I have answered you question.

    Ken

  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to determine is mouse click was on a label

    Sorry about that - I should have indicated the version...

    VS2005

    and the worse part - Mobile CE app - there is no click event for a label.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [VS2005/CE] How to determine is mouse click was on a label

    I really can't check because I cannot run the program on the computer but could you do something like this?

    Yay Code:
    1. Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click
    2.         If sender.ToString() = "Label1" Then
    3.  
    4.         End If
    5. End Sub

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [VS2005/CE] How to determine is mouse click was on a label

    Nope - SENDER.TOSTRING returns APC.APC - which is the project and form name.

    Somehow I think I have to use the MOUSEPOINTER - but it's not aligning sensibly with the TOP/LEFT/HEIGHT/WIDTH of the label.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [VS2005/CE] How to determine is mouse click was on a label

    Well I know a really crappy way to do it.. but I know you won't like it. I have an idea though, so hold on

  8. #8
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [VS2005/CE] How to determine is mouse click was on a label

    Nevermind, I have no clue. lol

  9. #9

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [VS2005/CE] How to determine is mouse click was on a label

    Ok - I'm trying to use MOUSEPOSITION.X and .Y in the FORM_CLICK event and comparing it to a LABEL TOP/LEFT/WIDTH and HEIGHT.

    And apparently the MOUSEPOSITION includes the "top line" of the form but the x/y of the label does not include that area.

    Any ideas on how to measure or realize the size of the top bar on the form?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    Re: [VS2005/CE] How to determine is mouse click was on a label

    Maybe this can help http://www.vbforums.com/showthread.php?t=455971. This thread shows how to add a click event to a rectangle, so perhaps you could draw a rectangle where your label is and then monitor the click event for the rectangle.

    Helpful Links:
    VB 6 - How to get the "Key" Value in a collection
    VB.NET - File Search Utility || VB.NET - How to compare 2 directories || VB.NET - How to trust a network share
    VB.NET - Create Excel Spreadsheet From Array || VB.NET - Example Code & Hints you may not know
    VB.NET - Save JPEG with a certain quality (image compression) || VB.NET - DragDrop Files, Emails, and Email Attachments

    Please post some of the code you need help with (it makes it easier to help you)
    If your problem has been solved then please mark the thread [RESOLVED].
    Don't forget to Rate this post

    "Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-

  11. #11

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [VS2005/CE] How to determine is mouse click was on a label

    I started using the MOUSEDOWN event - it's working much better.

    Code:
        Private Sub APC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
            Label.Text = MousePosition.X.ToString & " " & MousePosition.Y.ToString
        End Sub
    
        Private Sub APC_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
            lblStatus.Text = e.X.ToString & " " & e.Y.ToString
        End Sub
    The _CLICK takes into account the "top bar" and the _MOUSEDOWN is the useable area of the FORM - and that's what the label placement is based on.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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