Hi , i have a list box and i want that when the user hovers over an item , a form is shown next to the mouse and stays as long as the mouse is over that item then disappears after the mouse leaves the item.
I Know how to show the form and how to handle the item hover event in the list box , all i am missing is how to show the form by the mouse..
Any Help ??
Thnx in advanced...

Recommended Answers

All 5 Replies

Hi,

If I understand well your problem, then, before showing the form, set its position (Top and Left properties) depending on the mouse position: MousePosition.X and MousePosition.Y (Control.MousePosition is contained by System.Windows.Forms).

Cheers,
Ionut

Shouldn't be anything more complicated than

Form1 F = new Form1();
            F.Show();
            F.SetDesktopLocation(Cursor.Position.X, Cursor.Position.Y);

if you use Control.MousePosition you will have to convert pointtoscreen.

commented: Good explanation! +6

Im curious, why are you using a form? Are you trying to produce a custom pop-up? I usually use a panel which i position then show/hide rather than using a seperate form. If you use a form i think it will get focus when opened which may fire off extra mouse events.
Also, the mousehover event only fires once, you need to move the mouse out of the control and reenter it to fire it a second time so might be worth checking the manual hover with a timer discussed in this thread.

I do actually prefer the form method, as its easier to reuse the code and can be handled quite nicely, for example using a Alpha blended layered window call to create a beautiful help balloon with transparency and rounded edges, or even a arrow pointing to a problem setting.

a form or even a application doesn't need input focus to get mouse events, as they happen regardless of focus. (keys are an entirely different story) But as long as your pop-up form isn't in front of your control that invokes it, then it should work fine.

It is entirely possible to create a class that accepts a control and a string as params, and when called will draw the string to an image, use the image to create an alpha blended layered window, then get the position from the control and show on screen, automatically getting the mouse out event for the control and hiding after X amount of seconds of roll out, even using EX_Animate_window to fade out the image form.

but to each their own, one thing I have always believed, and that is if your program does what you originally intended it to do, then you did it right, no matter how you did it.

Best of luck.

DiamondDrake is totally right, there is no single 'right' way to do something in code (although there are many many wrong ways :p ), i have played around with using a popup form in the past but had some problems with positioning it when it appeared etc. In the end i used a panel with a timer to create a grow and shrink animation to show/hide it. Wasnt all singing all dancing but it did exactly what it needed to do with zero problems :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.