8,834
社区成员
发帖
与我相关
我的任务
分享
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)
{
if (m.Msg == WM_LBUTTONUP)
{
ReleaseCapture();
MessageBox.Show("你要执行的代码");
SetCapture(this.Handle);
return;
}
base.WndProc(ref 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();
}