|
-
Jun 11th, 2005, 04:49 PM
#1
Thread Starter
Hyperactive Member
Making a Label's position where the mouse clicks.{RESOLVED]
Hello,
I am having my program let the user click on a picturebox in the form and it will create a Label that says hey!
The only problem I am having is what happens when I click and create the label the label goes to the top left corner of the Pic box.
How can I have it place the Label where the mouse clicks on the Picture box?
VB Code:
Static LabelNumber As Long
LabelNumber = LabelNumber + 1
Set m_myLabel = Me.Controls.Add("VB.Label", "Label" & CStr(LabelNumber), Picture1)
m_myLabel.Visible = True
m_myLabel.Caption = "HEY!"
Thank you and have a great day!
Stilekid007
Last edited by stilekid007; Jun 11th, 2005 at 06:09 PM.
-
Jun 11th, 2005, 04:53 PM
#2
Re: Making a Label's position where the mouse clicks.
You need to set the .Top and .Left properties each time. You could use X and Y of the mouse click if you trapped it.
-
Jun 11th, 2005, 05:20 PM
#3
Re: Making a Label's position where the mouse clicks.
VB Code:
m_myLabel.Move 100,150, 500, 400
DO this in the MouseDown event and in the above code replace 100,150 with X and Y.
Praddep
-
Jun 11th, 2005, 05:47 PM
#4
Thread Starter
Hyperactive Member
Re: Making a Label's position where the mouse clicks.
Hello,
Thank you for your responses! Does anyone know the code for trapping the Mouse Position?
I haven't learned enough about VB to know all that!
Thank you all!
Stilekid007
-
Jun 11th, 2005, 05:52 PM
#5
Re: Making a Label's position where the mouse clicks.
Lots of controls have a mousedown, even the form. this will get you the x and y coords for the mouse at where it clicked.
-
Jun 11th, 2005, 05:59 PM
#6
Thread Starter
Hyperactive Member
Re: Making a Label's position where the mouse clicks.
AHH YES! Now I got! Thank you dglienna!
-
Jun 12th, 2005, 12:52 AM
#7
Re: Making a Label's position where the mouse clicks.{RESOLVED]
If for whatever reason you can't use a _mouse event then you can also use GetCursorPos.
VB Code:
Public Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" _
(ByRef lpPoint As POINTAPI) _
As Long
That returns the mouse position on the screen, in pixels. You then have to do some maths to get the relative position on your form.
-
Jun 12th, 2005, 01:08 AM
#8
Thread Starter
Hyperactive Member
Re: Making a Label's position where the mouse clicks.{RESOLVED]
Alright Thank You Penagate!
Very Helpfull! 
Stilekid007
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
|