惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
G
GRAHAM CLULEY
H
Hackread – Cybersecurity News, Data Breaches, AI and More
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Security Affairs
The Cloudflare Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
V2EX - 技术
V2EX - 技术
罗磊的独立博客
F
Full Disclosure
Jina AI
Jina AI
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
雷峰网
雷峰网
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
K
Kaspersky official blog
V
Visual Studio Blog
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Tor Project blog
Cloudbric
Cloudbric
Hacker News - Newest:
Hacker News - Newest: "LLM"
爱范儿
爱范儿
L
LINUX DO - 最新话题
GbyAI
GbyAI
Attack and Defense Labs
Attack and Defense Labs
H
Heimdal Security Blog
Recent Announcements
Recent Announcements
L
LINUX DO - 热门话题
L
LangChain Blog
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - williambirkin

.NET平台自带的AOP机制 转自《设计模式--基于c#的工程化实现及扩展》 今天看PolicyInjection遇到的问题 我的第一个ASP.NET Ajax控件 转 事务隔离级别 转 UML 基础: 类图 关于Form.show的问题 关于where中子查询的性能问题 请高手指教 模式 转 SQL Server 索引结构及其使用 (三) 转 SQL Server 索引结构及其使用 (二) 转 SQL Server 索引结构及其使用 (一) 泛型的一点思考 摘自《.NET 2.0 模式开发实战》 转 《为Windows应用创建简单的异步调用模式》 转 C#格式化数值结果表(格式化字符串) SQL游标的简单使用 转“理解VC# 2005中的字符串和正规表达式” 2个IP输入控件 回车移动焦点 文本框事件顺序
Windows Forms中禁用窗体的关闭按钮
williambirkin · 2007-05-10 · via 博客园 - williambirkin

1. Windows Forms中禁用窗体的关闭


添加必要的命名空间:

using System.Runtime.InteropServices;


添加必要的常数和
API函数的引用

private const int SC_CLOSE = 0xF060;

private const int MF_ENABLED = 0x00000000;

private const int MF_GRAYED = 0x00000001;

private const int MF_DISABLED = 0x00000002;

[DllImport("user32.dll", EntryPoint = "GetSystemMenu")]

private static extern IntPtr GetSystemMenu(IntPtr hWnd, int bRevert);

[DllImport("User32.dll")]

public static extern bool EnableMenuItem(IntPtr hMenu, int uIDEnableItem, int uEnable);


在窗体的
Load事件处理函数内添加代码

private void Form6_Load(object sender, EventArgs e)

{
   
IntPtr hMenu = GetSystemMenu(this.Handle, 0);
   EnableMenuItem(hMenu, SC_CLOSE, MF_DISABLED | MF_GRAYED);

}

2. Windows Forms中禁用窗体的关闭钮和ALT+F4关闭

protected override CreateParams CreateParams

{
   
get
   {
      const int CS_NOCLOSE = 0x200;
      CreateParams cp = base.CreateParams;
      cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
      return cp;
   }

}