A control is made, where the mouse moves to a Label and a panel appears. Then, the mouse moves the panel from the label or removes the panel from the panel to disappear.
Two problems were encountered:
1. Problems with the position of this panel.
Use this. FindForm (). Controls. Add (panel); to Add the panel. But there is a problem with Location, panel. location = new Point (Label. location. x, Label. lcation. y); the Label position of the control is (0, 0). When it is added, it is added to the outermost form (0, 0. So we found the absolute coordinates. Replace:
Point p = Label. PointToScreen (this. FindForm (). Location );
P. Y + = Label. Height;
Panel. Location = p;
You can.
2. calculate whether the mouse is in the panel.
Rectangle rect = panel. Bounds;
Int x = MousePosition. X-this. FindForm (). Left;
Int y = MousePosition. Y-this. FindForm (). Top;
If (x <= rect. Left | x> = rect. Right | y <= rect. Top | y> = rect. Bottom)
{
// The mouse is not in the panel
}
Else
{
// Place the cursor in the panel.
}
Author: "column of yysyangyangyangshan"