Results 1 to 8 of 8

Thread: [RESOLVED] Click a label on a form

  1. #1

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

    Resolved [RESOLVED] Click a label on a form

    I posted this in the VB.Net forum - but I'm thinking it might be a MOBILE specific issue...

    http://www.vbforums.com/showthread.p...45#post2833045

    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?

    *** 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
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Click a label on a form

    Hi,
    the label doesn't expose a click event in compact framework. The label at www.opennetcf.org does, as does the one at http://www.mozzak.com./ or you could use a picture box.

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

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

    Re: Click a label on a form

    I tried messing with the mouse position in the form_click event - any idea on how those values relate to the label position. It wasn't making much sense to me.

    *** 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

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Click a label on a form

    Hi,
    this works for me - not elegantly but...

    Code:
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
            If e.X >= Label1.Left And e.X <= Label1.Left + Label1.Width And e.Y >= Label1.Top And e.Y <= Label1.Top + Label1.Height Then
                MessageBox.Show("Click")
            End If
        End Sub
    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5

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

    Re: Click a label on a form

    That method is fine by me...

    btw...

    The MOUSEDOWN event and the CLICK event return different values...

    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

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Click a label on a form

    Put the label on a panel of the same size as the label. The panel will give you the click event. I have used this technique to create a multi-select list box by setting up several labels on several panels. It works pretty slick, and is MUCH easier than making your own control.
    My usual boring signature: Nothing

  7. #7

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

    Re: Click a label on a form

    The MOUSEDOWN is working fine - I don't think I need the extra baggage of more GUI objects and events.

    But thanks for the suggestion!

    *** 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

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: [RESOLVED] Click a label on a form

    Keep that suggestion in mind in case you ever have to do a multi-select listbox. That's what I figured it out for. It was the only way to go in 2003. I haven't looked to see whether multi-select is an option in 2005.

    Also, it is only one more GUI object, no more events, as it would replace the MouseDown, without any question as to where the mouse was pressed.
    My usual boring signature: Nothing

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