110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime .InteropServices ;
namespace WindowsApplication242
{
public partial class Form1 : Form
{
[DllImport("user32")]
static extern IntPtr GetSystemMenu(IntPtr hwnd, int bRevert);
[DllImport("user32")]
static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);
int MF_GRAYED = 1;
int MF_BYCOMMAND = 0;
int SC_CLOSE = 0xF060;
public Form1()
{
InitializeComponent();
EnableMenuItem(GetSystemMenu(this.Handle, 0),
SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
}
}
}
//窗体的FormClosing事件处理器
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
//最大化时不能关闭
e.Cancel = true;
}
protected override void OnClosing(CancelEventArgs e)
{
if(this.Visible)
{
e.Cancel=true;
}
}