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

推荐订阅源

V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
NISL@THU
NISL@THU
T
Tor Project blog
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
O
OpenAI News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
V2EX - 技术
V2EX - 技术
H
Help Net Security
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
Forbes - Security
Forbes - Security
人人都是产品经理
人人都是产品经理
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
I
InfoQ
Schneier on Security
Schneier on Security
K
Kaspersky official blog
罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Security Affairs
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
雷峰网
雷峰网
G
GRAHAM CLULEY
Cloudbric
Cloudbric
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
AI
AI
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
博客园_首页
T
Threat Research - Cisco Blogs
S
Secure Thoughts
有赞技术团队
有赞技术团队

博客园 - 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;
   }

}