.NET运行界面上,实现随意拖动控件的方法
using System.Windows.Forms;
namespace WinFormsApp_DragControls
{
public class DragControl
{
//待拖动的控件
private Control m_Control;
//鼠标按下时的x,y坐标
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;
}
}
}
}
调用:
DragControl obj1 = new DragControl(button1);
则表示在运行的界面上,支持随意拖动button1
另外还可以进一步实现改变控件大小、GDI+实现加边界脚点、保存控件的位置到xml下次可以读取(布局)以及自动布局N个Control的算法等,想进一步了解可与本人联系,此处不多叙述..
相关文章
asp.net 使用Silverlight操作ASPNETDB数据库
asp.net下使用Silverlight操作ASPNETDB数据库的实现代码2010-01-01ASP.NET Core 6.0 添加 JWT 认证和授权功能
这篇文章主要介绍了ASP.NET Core 6.0 添加 JWT 认证和授权,本文将分别介绍 Authentication(认证) 和 Authorization(授权),通过实例代码分别介绍了这两个功能,需要的朋友可以参考下2022-04-04asp.net html控件的File控件实现多文件上传实例分享
asp.net中html控件的File控件实现多文件上传简单实例,开发工具vs2010使用c#语言,感兴趣的朋友可以了解下,必定是多文件上传值得学习,或许本文所提供的知识点对你有所帮助2013-02-02
最新评论