C# 调用SendMessage来移动窗口
在我winform的click和move都放进了SendMessage(this.handle,161,2,0);来移动,但是测试好像不可以移动,该怎么移动?...
在我winform的click和move都放进了
SendMessage(this.handle,161,2,0);
来移动,但是测试好像不可以移动,该怎么移动? 展开
SendMessage(this.handle,161,2,0);
来移动,但是测试好像不可以移动,该怎么移动? 展开
1个回答
展开全部
...在你需要能拖动窗体的控件中添加MouseDown事件的处理,比如一个图片框:
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x112;
public const int HTCAPTION = 0x0002;
public const int SC_MOVE = 0xF010; //移动
private void picDemo_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//调动系统函数移动窗体
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x112;
public const int HTCAPTION = 0x0002;
public const int SC_MOVE = 0xF010; //移动
private void picDemo_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//调动系统函数移动窗体
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询