public Point CPoint; //添加命名空间using System.Drawing;
#region 利用窗体上的控件移动窗体
/// <summary>
/// 利用控件移动窗体
/// </summary>
/// <param Frm="Form">窗体</param>
/// <param e="MouseEventArgs">控件的移动事件</param>
public void FrmMove(Form Frm, MouseEventArgs e) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = Control.MousePosition;//获取当前鼠标的屏幕坐标
myPosittion.Offset(CPoint.X, CPoint.Y);//重载当前鼠标的位置
Frm.DesktopLocation = myPosittion;//设置当前窗体在屏幕上的位置
}
}
#endregion
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.CPoint = new Point(-e.X, -e.Y);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
this.FrmMove(this, e);
}