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 :wave:
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.
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 :)
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
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.
Re: Making a Label's position where the mouse clicks.
AHH YES! Now I got! Thank you dglienna!
:wave:
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.
Re: Making a Label's position where the mouse clicks.{RESOLVED]
Alright Thank You Penagate!
Very Helpfull! :thumb:
Stilekid007 :wave: