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

C#运行时鼠标移动控件 - 调用Windows API(ReleaseCapture)

2016-09-15 10:54 253 查看
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool ReleaseCapture();

private void MoveControl(Control sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
ReleaseCapture();
SendMessage(sender.Handle, 161, 2, 0);
SendMessage(sender.Handle, 0x0202, 0, 0);
}
else
{
//添加双击或右击代码……
}
}

private void button3_MouseDown(object sender, MouseEventArgs e)
{
MoveControl(sender as Control, e);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐