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

推荐订阅源

AI
AI
T
Tailwind CSS Blog
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
P
Proofpoint News Feed
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
博客园 - Franky
The GitHub Blog
The GitHub Blog
月光博客
月光博客
小众软件
小众软件
Martin Fowler
Martin Fowler
P
Palo Alto Networks Blog
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
T
Threat Research - Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
Spread Privacy
Spread Privacy
博客园 - 聂微东
B
Blog
The Hacker News
The Hacker News
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Privacy International News Feed
腾讯CDC
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threatpost
T
Tenable Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Heimdal Security Blog

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

}