C# 捕获鼠标
方式一-API
/// <summary> /// 捕获鼠标 /// </summary> /// <param name="hwnd"></param> /// <returns></returns> [DllImport("user32.dll", SetLastError = true)] public static extern bool SetCapture(IntPtr hwnd); /// <summary> /// 释放鼠标 /// </summary> /// <returns></returns> [DllImport("user32.dll", SetLastError = true)] public static extern bool ReleaseCapture()
方式二
Control.Capture;
通过捕获鼠标改变指针
Cursor cursor; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Bitmap bitmap = Properties.Resources._111; cursor = new Cursor(bitmap.GetHicon()); pictureBox1.Cursor = cursor; SetCapture(pictureBox1.Handle); bitmap.Dispose(); } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { cursor.Dispose(); ReleaseCapture(); pictureBox1.Cursor = Cursors.Default; }
转载请注明出处。