WInForm右上角关闭按钮消息捕获与事件修改
程序员文章站
2022-06-08 23:13:06
...
/// <summary>
/// winform右上关闭按钮事件修改
/// </summary>
/// <param name="msg">message</param>
protected override void WndProc(ref Message msg)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
try
{
if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE))
{
// 点击winform右上关闭按钮
// 加入想要的逻辑处理
return;
}
base.WndProc(ref msg);
}
catch (Exception ex)
{
//消息事件修改失败
Console.WriteLine(ex.Message);
//处理原来的消息
base.WndProc(ref msg);
}
}在这里插入代码片