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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
V2EX - 技术
V2EX - 技术
K
Kaspersky official blog
Know Your Adversary
Know Your Adversary
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
Intezer
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
博客园 - Franky
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research
The Hacker News
The Hacker News
T
Tenable Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
雷峰网
雷峰网
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Webroot Blog
Webroot Blog
L
LangChain Blog
C
Check Point Blog
N
News | PayPal Newsroom
L
LINUX DO - 热门话题
T
Tor Project blog
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
S
Security Affairs
Schneier on Security
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Security Latest
Security Latest
MyScale Blog
MyScale Blog
Cyberwarzone
Cyberwarzone
N
Netflix TechBlog - Medium
Scott Helme
Scott Helme
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
人人都是产品经理
人人都是产品经理
W
WeLiveSecurity

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

}