在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
复制代码 代码如下: using System.Windows.Forms; namespace WinFormsApp_DragControls { { //待拖动的控件 private Control m_Control; //鼠标按下时的x,y坐标 private int m_X; private int m_Y; public DragControl(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; } int x = e.X - m_X; int y = e.Y - m_Y; this.m_Control.Left += x; this.m_Control.Top += y; 调用: DragControl obj1 = new DragControl(button1); 则表示在运行的界面上,支持随意拖动button1 |
请发表评论