none
textbox attached to mouse RRS feed

  • Question

  • Hi

    Im my application, i need to try and mimic a cross hair attached to mouse while over a large picturebox. Moreso, i would like to add a textbox to the mousepointer so that as i move the mouse, i get some co-ordinates.

    i have a function that is capturing a mouse move and i can attach a label that exists in the form to it but i would like to create them on the fly. It seems cleaner that way instead of using existing one.

    How can i create the label in code and add it to the mouse pointer with text?

    Cheers

    Nacho


    Nacho is the derivative of Nigel - True fact! I am self taught in VB.Net. 50% of the time, I am right 100% of the time!

    Sunday, September 24, 2017 3:40 AM

All replies

  • How can i create the label in code and add it to the mouse pointer with text?

    You can create a label on the fly. Just use the New method of the Label class.  Make sure you add the new object to the form's control collection so that it displays on the form. And, of course, set its properties to what you need. 

    Attach it to the mouse pointer as you are doing now - by updating the label position property according to the current cursor position. Set the variable to Nothing when finished.

    Sunday, September 24, 2017 4:41 AM
  • Hi

    I was doing everything you have suggested except the adding of the control to the forms collection.

    set it up currently with labels added to the form, i will change the label to adding them on the fly now, just because i feel it is neater :)

    Here is my current version with a crosshair & labels attached (to the mouse pointer)

    Nacho


    Nacho is the derivative of Nigel - True fact! I am self taught in VB.Net. 50% of the time, I am right 100% of the time!

    Sunday, September 24, 2017 5:55 AM
  • Hi

    I was doing everything you have suggested except the adding of the control to the forms collection.

    set it up currently with labels added to the form, i will change the label to adding them on the fly now, just because i feel it is neater :)

    Here is my current version with a crosshair & labels attached (to the mouse pointer)

    Nacho


    Nacho is the derivative of Nigel - True fact! I am self taught in VB.Net. 50% of the time, I am right 100% of the time!


     If you are creating new label(s) every time the mouse enters the PictureBox,  then remember not to forget to call the Dispose method of the New Label(s) before creating more New Label(s).  If you don't you could end up with hundreds or thousands of Labels pretty quickly.  That would be a BAD thing.

    If you say it can`t be done then i`ll try it

    Sunday, September 24, 2017 12:01 PM