C# winfrom 菜单加图标
- 提问者网友:野性
- 2021-02-07 01:30
- 二级知识专家网友:夢想黑洞
- 2021-02-07 02:27
- 1楼网友:许你一世温柔
- 2021-02-07 03:59
双击form_closing事件,然后直接写以下代码,使得窗体无法关闭:
private void form_formclosing(object sender, formclosingeventargs e) { e.cancel = true; }
c#中可没有直接屏蔽关闭按钮的方法,你硬要这样也可以:
[system.runtime.interopservices.dllimport("user32.dll")] static extern intptr getsystemmenu(intptr hwnd, bool brevert); [system.runtime.interopservices.dllimport("user32.dll")] static extern int getmenuitemcount(intptr hmenu); [system.runtime.interopservices.dllimport("user32.dll")] static extern bool drawmenubar(intptr hwnd); [system.runtime.interopservices.dllimport("user32.dll")] static extern bool removemenu(intptr hmenu, uint uposition, uint uflags); protected override void onload(eventargs e) { base.onload (e); const int32 mf_byposition = 0x400; const int32 mf_remove = 0x1000; intptr menu = getsystemmenu(this.handle, false); int menucount = getmenuitemcount(menu); if (menucount > 1) { //删除菜单的「关闭」和分隔符 removemenu(menu, (uint) (menucount - 1), mf_byposition | mf_remove); removemenu(menu, (uint) (menucount - 2), mf_byposition | mf_remove); drawmenubar(this.handle); }