Absolute coordinates of controls in the parent form or screen

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.