avatar
Articles
317
Tags
187
Categories
21
Home
Archieves
Tags
Categories
BIM
Devs
Link
About
Broccoli's DevWinForm重写右上角“关闭”按钮的方法 Back to Home
Search
Home
Archieves
Tags
Categories
BIM
Devs
Link
About

WinForm重写右上角“关闭”按钮的方法

Created2020-08-27|Updated2026-01-08|devwinform
|Post Views:
仅提供中文版本
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))
{
// 点击winform右上关闭按钮
// 加入想要的逻辑处理
return;
}
base.WndProc(ref msg);
}


链接地址:WinForm判断关闭事件来源于用户点击右上角“关闭”按钮的方法

Author: Broccoli
Link: https://xlx.dev/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 Method to Override "Close" Button in Upper Right Corner
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)) { // 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
Related Articles
cover
2021-08-31
Winform DataGridView Binding Resource Then Setting Row Height and Fill Image Setting
I bound resources of datagridview through datasource, adding rows in background by traversing dataTable, because there are images so need to modify column width and row height, but modifying several properties in property interface cannot intervene this action, after troubleshooting found, directly modify inside class adding Row works. Below is code: 123var dateRow = new DataGridViewRow(); dateRow.Height = 150; dateRow.CreateCells(this.dataGridView1); Image fill Colu...
cover
2021-03-02
Winform 调整SplitContainer中Panel的大小
点击Panel后点击ESC取消然后将鼠标移动到边界上即可调整大小
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-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
xlx.dev
Articles
317
Tags
187
Categories
21
Announcement
欢迎访问!右上角可切换中英文。感谢您的阅读!
Recent Posts
Quickly Migrate Blog Using YingDao
Quickly Migrate Blog Using YingDao2026-01-07
使用影刀快速迁移博客
使用影刀快速迁移博客2026-01-07
LLaMA-Factory Gradio Environment Configuration
LLaMA-Factory Gradio Environment Configuration2026-01-04
LLaMA-Factory Gradio 环境配置
LLaMA-Factory Gradio 环境配置2026-01-04
VS Code SSH Remote Connection Issues
VS Code SSH Remote Connection Issues2026-01-04
© 2025 - 2026 By BroccoliFramework Hexo 8.1.1|Theme Butterfly 5.5.2
Search
Loading Database