当前位置: 代码迷 >> C# >> 怎么通过webbrowser拖动form
  详细解决方案

怎么通过webbrowser拖动form

热度:3917   发布时间:2013-02-25 00:00:00.0
如何通过webbrowser拖动form
form是无边框,在web里面做标题栏,如何实现点web里面这个标题栏来拖动winfrom 的窗体?
webbrowser form

------解决方案--------------------------------------------------------
既然网页是你的,那你网页内自己写好交互用的js。
当你keydown网页内的标题栏时,js给winform个消息,winform收到消息后执行个方法,
这个方法类似这样:
private void MoveWindow()
{ // 给当前窗体发送个WM_LBUTTONDOWN 消息
  PostMessage((int)this.Handle, 0x0201, 0, 0);
}

//在窗体的mousedown下做窗口移动处理
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
  ReleaseCapture();
  PostMessage((int)this.Handle, 0x0112, 0xf012, 0);
}

// 当然要引入这几个api
using System.Runtime.InteropServices;
[DllImport("user32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(
 int hwnd,int wMsg,int wParam,int lParam
);
[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern int ReleaseCapture();

// 没条件测试,你自己测试下吧
  相关解决方案