如何使用C#编码在Windows窗体中禁用“closures”button

每一个。 我只想使用C#.net在button单击事件上禁用“closures”button。 我正在尝试,但不正确的确定它是正确的。

private void button1_Click(object sender, EventArgs e) { this.ControlBox = false; } 

Solutions Collecting From Web of "如何使用C#编码在Windows窗体中禁用“closures”button"

添加以下库

 using System.Runtime.InteropServices; 

将以下内容声明为类级变量

 const int MF_BYPOSITION = 0x400; [DllImport("User32")] private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags); [DllImport("User32")] private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport("User32")] private static extern int GetMenuItemCount(IntPtr hWnd); 

在Form_Load()事件中,编写下面的代码

 private void Form1_Load(object sender, EventArgs e) { IntPtr hMenu = GetSystemMenu(this.Handle, false); int menuItemCount = GetMenuItemCount(hMenu); RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION); 

}

禁用关闭“X”按钮

只需修改您的ClickEvent

 private const int dis_close_button = 0x200; protected override CreateParams CreateParams { get { CreateParams ObjCP = base.CreateParams; ObjCP.ClassStyle = ObjCP.ClassStyle | dis_close_button; return ObjCP; } } 

尝试这个…