avatar
Articles
331
Tags
204
Categories
24
Home
Archieves
Tags
Categories
BIM
Devs
Link
About
graptolite's DevWinForm Method to Override "Close" Button in Upper Right Corner Back to Home
Search
Home
Archieves
Tags
Categories
BIM
Devs
Link
About

WinForm Method to Override "Close" Button in Upper Right Corner

Created2020-08-27|Updated2026-02-05|devwinform
|Post Views:
仅提供English版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
protected override void WndProc(ref Message msg)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE))
{
// Click close button on winform upper right
// Add wanted logic processing
return;
}
base.WndProc(ref msg);
}


Link Address:Method to judge close event comes from user clicking “Close” button in upper right corner in WinForm

Author: Broccoli
Link: https://graptolite.ai/winform-override-close-button/
Copyright Notice: All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
winformbutton
cover of previous post
Previous
Revit Secondary Development Get Location of Multi-segment Grid
Clicking multi-segment grid will find grid type is MultiSegmentGrid, there is no Location to get inside. If want to get path can get through two waysWay 1:In Revit can edit sketch mode can collect component ID by deleting component to get corresponding pathCode can refer to Ye Xiongjin’s article on getting slab boundary to getWay 2: Directly Collector collect all Grid types, grids with same Name inside are multi-segment grids 12var list = collector.OfCategory(BuiltInCategory.OST_Grids).ToList...
cover of next post
Next
WinForm重写右上角“关闭”按钮的方法
1234567891011121314protected override void WndProc(ref Message msg){ const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE)) { // 点击winform右上关闭按钮 // 加入想要的逻辑处理 return; } base.WndProc(ref msg);} 链接地址:WinForm判断关闭事件来源于用户点击右上角“关闭”按钮的方法
Related Articles
cover
2020-07-09
Winform DatagridCombox绑定数据显示无法对设置了 DataSource 的组合框排序。请使用基础数据模型对数据排序
今天使用winform创建datagridview其中绑定了combox数据 1234name.DataPropertyName = "PropertyName"; name.DisplayMember = "pn_name"; name.ValueMember = "pn_id"; name.DataSource = GetNames().Tables[0]; 项目报错:无法对设置了 DataSource 的组合框排序。请使用基础数据模型对数据排序对照多个博客发现自己的赋值并没有问题,看到最后一句使用使用基础数据,便点开编辑列发现设置sorted为true设置为false后错误消失
cover
2021-08-31
Winform DataGridView 绑定资源后设置行高与布满图片的设置
我通过datasource绑定了datagridview的资源,通过遍历dataTable后台增加行,因为有图片所以需要修改列宽与行高,但是修改属性界面中的几个属性都无法干预这个动作,排查后发现,直接在增加Row的类里面修改即可。下面是code: 123var dateRow = new DataGridViewRow(); dateRow.Height = 150; dateRow.CreateCells(this.dataGridView1); 图片布满ColumnItem在属性里面将Normal修改为Zoom即可
cover
2021-03-02
Winform Resize Panel in SplitContainer
Click Panel then click ESC to cancel then move mouse to boundary to resize
cover
2021-03-15
Revit Winform Display on Top of Revit
Reference Article: 《BuilderCoder Revit Parent Window 》 When we use modal form, when focus is not on form, form will hide behind all layers. If encountering unfamiliar user, will click buttons continuously, creating multiple forms. And interaction for single form is also not friendly. Searching in website, often tell everyone to set TopMost, but this operation sets form to top most layer. When we use other applications like browser, form still displays on top layer which does not conform to in...
avatar
Broccoli
graptolite.ai
Articles
331
Tags
204
Categories
24
Announcement
欢迎访问!右上角可切换中英文。感谢您的阅读!
Recent Posts
Google Chrome Built-in Multimodal Model (Gemini Nano) Local Setup Guide
Google Chrome Built-in Multimodal Model (Gemini Nano) Local Setup Guide2026-02-05
Google Chrome 内置多模态模型(Gemini Nano)本地部署指南
Google Chrome 内置多模态模型(Gemini Nano)本地部署指南2026-02-05
Gemini in Chrome 浏览器AI助手
Gemini in Chrome 浏览器AI助手2026-02-05
Gemini in Chrome: Your Personal AI Assistant Inside the Browser
Gemini in Chrome: Your Personal AI Assistant Inside the Browser2026-02-05
Chrome DevTools AI Assistant Guide
Chrome DevTools AI Assistant Guide2026-02-05
© 2025 - 2026 By BroccoliFramework Hexo 8.1.1|Theme Butterfly 5.5.2
Search
Loading Database