您的位置:首页 > 编程语言 > C#

.net c#拖动控件,移动控件位置

2007-10-11 08:22 302 查看

private Point mouse_offset;




private void label1_MouseDown(object sender, MouseEventArgs e)




...{


mouse_offset = new Point(-e.X, -e.Y);//




}




private void label1_MouseMove(object sender, MouseEventArgs e)




...{


((Control)sender).Cursor = Cursors.Arrow;//设置拖动时鼠标箭头


if (e.Button == MouseButtons.Left)




...{


Point mousePos = Control.MousePosition;


mousePos.Offset(mouse_offset.X, mouse_offset.Y);//设置偏移


((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);


}




}


参考:http://www.cnblogs.com/DS-CzY/archive/2007/06/30/801377.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: