2011-04-08 36 views
0

可能重複形式的關閉按鈕:
How to make the Close button disabled in a windows Form using C# coding如何使禁用

我想在形式禁用關閉按鈕任何一個可以幫我在這。

+2

OK,我們在這裏需要一大堆的更多信息。你在WinForms,WPF,Silverlight或ASP.NET中工作嗎? – 2011-04-08 07:10:48

+0

你的意思是右上角的'x'按鈕? – 2011-04-08 07:12:41

+1

投票關閉作爲重複的[This](http://stackoverflow.com/questions/5580512/how-to-make-the-close-button-disabled-in-a-windows-form-using-c-coding ) – V4Vendetta 2011-04-08 07:17:27

回答

0

以下應該有所幫助:

[DllImport("user32.dll")] 
private static extern int GetSystemMenu(int hwnd, int revert); 

[DllImport("user32.dll")] 
private static extern int GetMenuItemCount(int menu); 

[DllImport("user32.dll")] 
private static extern int RemoveMenu(int menu, int position, int flags); 

private void DisableCloseButton() 
{ 
    int menu = GetSystemMenu(Handle.ToInt32(), 0); 
    int count = GetMenuItemCount(menu); 
    RemoveMenu(menu, count - 1, MF_DISABLED | MF_BYPOSITION); 
}