Click to See Complete Forum and Search --> : [RESOLVED] Click a label on a form
szlamany
Apr 2nd, 2007, 10:43 AM
I posted this in the VB.Net forum - but I'm thinking it might be a MOBILE specific issue...
http://www.vbforums.com/showthread.php?p=2833045#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?
petevick
Apr 2nd, 2007, 12:11 PM
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
szlamany
Apr 2nd, 2007, 12:18 PM
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.
petevick
Apr 2nd, 2007, 01:04 PM
Hi,
this works for me - not elegantly but...
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
szlamany
Apr 2nd, 2007, 01:25 PM
That method is fine by me...
btw...
The MOUSEDOWN event and the CLICK event return different values...
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.
Shaggy Hiker
Apr 2nd, 2007, 10:13 PM
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.
szlamany
Apr 3rd, 2007, 04:01 PM
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!
Shaggy Hiker
Apr 3rd, 2007, 10:23 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.