我有一个模态对话框想在鼠标点击窗口外的地方时执行一段代码
var form=new Form1();
form.showDialog();
有人说用 SetCapture();
我在form中加了SetCapture(this) 后该怎么做
WndProc(ref Message m) 里还是得不到鼠标的消息
------最佳解决方案--------------------------------------------------------
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr h);
private void Form2_Load(object sender, EventArgs e)
{
SetCapture(this.Handle);
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
ReleaseCapture();
}
private void Form2_MouseUp(object sender, MouseEventArgs e)
{
Close();
}
------其他解决方案--------------------------------------------------------
这次好像粘错代码了
------其他解决方案--------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr h);
private readonly Int32 WM_LBUTTONUP = 0x202;
private void Form1_Load(object sender, EventArgs e)
{
SetCapture(this.Handle);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ReleaseCapture();
}
protected override void WndProc(ref Message m)