您的位置:首页 > 其它

class for Dragging Form in .NET

2006-04-12 10:07 246 查看
internal class FormDrag
{
Form _form=null ;
int _y = 0, _x = 0;
private bool _mousedown = false;

public FormDrag(Form form)
{

if (form == null)
throw new ArgumentNullException("Must pass a form instance.");
_form = form;
_form.MouseMove += new MouseEventHandler(_form_MouseMove);
_form.MouseDown += new MouseEventHandler(_form_MouseDown);
_form.MouseUp += new MouseEventHandler(_form_MouseUp);

}

void _form_MouseUp(object sender, MouseEventArgs e)
{
_mousedown = false;
}

void _form_MouseDown(object sender, MouseEventArgs e)
{
_mousedown = true;
_y = e.Y;
_x = e.X;

}

void _form_MouseMove(object sender, MouseEventArgs e)
{

if (_mousedown)
{
int a = _y - e.Y;
_form.Top -= a;
a = _x - e.X;
_form.Left -= a;

}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐