Results 1 to 8 of 8

Thread: Making a Label's position where the mouse clicks.{RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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:
    1. Static LabelNumber As Long
    2.  
    3.         LabelNumber = LabelNumber + 1
    4.         Set m_myLabel = Me.Controls.Add("VB.Label", "Label" & CStr(LabelNumber), Picture1)
    5.         m_myLabel.Visible = True
    6.         m_myLabel.Caption = "HEY!"

    Thank you and have a great day!
    Stilekid007
    Last edited by stilekid007; Jun 11th, 2005 at 06:09 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Making a Label's position where the mouse clicks.

    VB Code:
    1. 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
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  6. #6

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Making a Label's position where the mouse clicks.

    AHH YES! Now I got! Thank you dglienna!


  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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:
    1. Public Type POINTAPI
    2.     X As Long
    3.     Y As Long
    4. End Type
    5.  
    6. Private Declare Function GetCursorPos Lib "user32" _
    7.     (ByRef lpPoint As POINTAPI) _
    8.     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.

  8. #8

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    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
  •  



Click Here to Expand Forum to Full Width