关于winform移动控件
我用的是程序代码:
private bool isMouseMove = false;//获取鼠标是否游动 private Point mouseOffset; //记录鼠标指针的坐标 protected void temp_MouseDown(object sender, MouseEventArgs e) { //当鼠标点击左键 执行对应操作 if (e.Button == MouseButtons.Left) { isMouseMove = false; } protected void temp_MouseMove(object sender, MouseEventArgs e) { //Bitmap img = new Bitmap(temp.Image); //temp.DrawToBitmap(img, temp.Bounds); if (isMouseMove == false) { mouseOffset.X = e.X; mouseOffset.Y = e.Y; isMouseMove = true; return; } if (isMouseMove == true) { int left = temp.Left + e.X - mouseOffset.X; int top = temp.Top + e.Y - mouseOffset.Y; temp.Location = new Point(left, top); } }
来移动一个 picturebox控件 但是 移动的过程总是有重影
我想用API的方式进行移动
程序代码:
[DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private void frmMain_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, 0x0112, 0xF012, 0); }
但是 它是一个 MouseDown 鼠标点击着控件才能移动,我把frmMain_MouseDown 这个方法关联到 mousemove 事件中,但是不起效
所以想请大家帮帮忙