I am struggling with something that I think should be easily (ish). I have a windows form and a flowgridlayout panel at the bottom of the form. Inside this form I dynamically populate it with X number of User Controls. The controls are all the same type.
The goal is when the user hoovers the mouse over the user control it opens another form and positions it where the mouse is. When mouse leaves the form the opened form disappears.
This almost works great. The problem is when the User Control has anything like a label or text box inside it. It is considered to have left the UC so the form disappears.
My thought was then to use the X and Y to tell if it is inside the UC but I can not figure this out.
Can I ask:
1) What is the best approach to this? 2) How can I code it, as the UC's are dynamic I can not know exactly where they will be.
Thanks
EDIT
I am trying to figure out the mouse pointers but not getting there. The code below is within the UC SmallTagBox_MouseLeave event:
Point loc = this.Location;
Point p = this.PointToScreen(this.Location);
Point p2 = this.PointToScreen(this.Parent.Location);
Point ms = MousePosition;
Rectangle screenBounds = new Rectangle(this.PointToScreen(this.Location), this.Size);
if (!screenBounds.Contains(ms))
{
thw.Close();
thw = null;
}
- loc {X = 275 Y = 3} System.Drawing.Point
- p {X = 808 Y = 908} System.Drawing.Point
- p {X = 808 Y = 908} System.Drawing.Point
- p2 {X = 545 Y = 1542} System.Drawing.Point
- ms {X = 574 Y = 914} System.Drawing.Point
- screenBounds {X = 808 Y = 908 Width = 62 Height = 29} System.Drawing.Rectangle
I do not understand how p2 (its parent) can have a greater Y value relative to the screen.