The. NET running interface allows you to drag controls at will.

Source: Internet
Author: User

Copy codeThe Code is as follows: using System. Windows. Forms;

Namespace WinFormsApp_DragControls

{
Public class DragControl

{

// Controls to be dragged

Private Control m_Control;

// X and y coordinates when the mouse is pressed

Private int m_X;

Private int m_Y;

Public DragControl (Control control)
{
M_Control = control;

M_Control.MouseDown + = new MouseEventHandler (control_MouseDown );

M_Control.MouseMove + = new MouseEventHandler (contro_MouseMove );

}

Private void control_MouseDown (object sender, MouseEventArgs e)
{

M_X = e. X;

M_Y = e. Y;

}
Private void contro_MouseMove (object sender, MouseEventArgs e)
{
If (e. Button = MouseButtons. Left)
{

Int x = e. X-m_X;

Int y = e. Y-m_Y;

This. m_Control.Left + = x;

This. m_Control.Top + = y;
}
}
}
}

Call:

DragControl obj1 = new DragControl (button1 );

It indicates that you can drag button1 at Will on the running interface.

In addition, you can further adjust the widget size, use GDI + to add a boundary foot point, save the widget location to xml, and then read (layout) and automatically layout N Control algorithms, for more information, please contact me ..

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.