|
-
Apr 2nd, 2007, 09:53 AM
#1
[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.
-
Apr 2nd, 2007, 10:07 AM
#2
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:
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
'...Enter your code
End Sub
-
Apr 2nd, 2007, 10:07 AM
#3
Hyperactive Member
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
-
Apr 2nd, 2007, 10:09 AM
#4
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.
-
Apr 2nd, 2007, 10:20 AM
#5
Frenzied Member
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:
Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click
If sender.ToString() = "Label1" Then
End If
End Sub
-
Apr 2nd, 2007, 10:26 AM
#6
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.
-
Apr 2nd, 2007, 10:33 AM
#7
Frenzied Member
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
-
Apr 2nd, 2007, 10:36 AM
#8
Frenzied Member
Re: [VS2005/CE] How to determine is mouse click was on a label
Nevermind, I have no clue. lol
-
Apr 2nd, 2007, 12:36 PM
#9
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?
-
Apr 2nd, 2007, 12:48 PM
#10
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.
-
Apr 2nd, 2007, 01:23 PM
#11
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|