|
-
Aug 25th, 2006, 04:26 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Add Label At Mouse Position
I am trying to add a label just where my mouse is using a context menu "Add Label" but it goes to a different position. How can i do this. Below is my code.
VB Code:
Private Sub cmnuAddLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuAddLabel.Click
Dim lbl As Label
lbl = New Label
lbl.Text = "My Lable"
AddHandler lbl.MouseDown, AddressOf MyEventHandler
lbl.Location = New System.Drawing.Point(Control.MousePosition.X, Control.MousePosition.Y)
Me.Controls.Add(lbl)
End Sub
Last edited by maps; Aug 25th, 2006 at 04:31 AM.
-
Aug 25th, 2006, 06:10 AM
#2
Hyperactive Member
Re: Add Label At Mouse Position
You need to capture the mouse position when you initially click the button, try this code.
VB Code:
Public Class Form2
Dim pt As Point
Private Sub cmnuAddLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuAddLabel.Click
Dim lbl As Label
lbl = New Label
lbl.Text = "My Lable"
AddHandler lbl.MouseDown, AddressOf MyEventHandler
lbl.Location = pt
Me.Controls.Add(lbl)
End Sub
Public Sub MyEventHandler(ByVal Sender As Object, ByVal e As MouseEventArgs)
' your event code here
End Sub
Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
pt = New Point(e.X, e.Y)
End Sub
End Class
-
Aug 25th, 2006, 06:38 AM
#3
Thread Starter
Hyperactive Member
Re: Add Label At Mouse Position
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
|