.NET運(yùn)行界面上,實(shí)現(xiàn)隨意拖動控件的方法
using System.Windows.Forms;
namespace WinFormsApp_DragControls
{
public class DragControl
{
//待拖動的控件
private Control m_Control;
//鼠標(biāo)按下時的x,y坐標(biāo)
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;
}
}
}
}
調(diào)用:
DragControl obj1 = new DragControl(button1);
則表示在運(yùn)行的界面上,支持隨意拖動button1
另外還可以進(jìn)一步實(shí)現(xiàn)改變控件大小、GDI+實(shí)現(xiàn)加邊界腳點(diǎn)、保存控件的位置到xml下次可以讀取(布局)以及自動布局N個Control的算法等,想進(jìn)一步了解可與本人聯(lián)系,此處不多敘述..
相關(guān)文章
ASP.NET2.0中數(shù)據(jù)源控件之異步數(shù)據(jù)訪問
ASP.NET2.0中數(shù)據(jù)源控件之異步數(shù)據(jù)訪問...2006-09-09asp.net 使用Silverlight操作ASPNETDB數(shù)據(jù)庫
asp.net下使用Silverlight操作ASPNETDB數(shù)據(jù)庫的實(shí)現(xiàn)代碼2010-01-01ASP.NET?Core?6.0?添加?JWT?認(rèn)證和授權(quán)功能
這篇文章主要介紹了ASP.NET?Core?6.0?添加?JWT?認(rèn)證和授權(quán),本文將分別介紹?Authentication(認(rèn)證)?和?Authorization(授權(quán)),通過實(shí)例代碼分別介紹了這兩個功能,需要的朋友可以參考下2022-04-04asp.net html控件的File控件實(shí)現(xiàn)多文件上傳實(shí)例分享
asp.net中html控件的File控件實(shí)現(xiàn)多文件上傳簡單實(shí)例,開發(fā)工具vs2010使用c#語言,感興趣的朋友可以了解下,必定是多文件上傳值得學(xué)習(xí),或許本文所提供的知識點(diǎn)對你有所幫助2013-02-02