XWL
asked on
How to disable or remove CLoseBox on the title bar?
Hi there,
I would like to disable or remove the Close Box on the title bar of my windows application. However, I want Max/Min boxes remain there.
Could anybody here tell me how? I am using C#.NET/Visual Studio 2005/Win2k.
Thank you,
XWL
I would like to disable or remove the Close Box on the title bar of my windows application. However, I want Max/Min boxes remain there.
Could anybody here tell me how? I am using C#.NET/Visual Studio 2005/Win2k.
Thank you,
XWL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you not try my code? It's much smaller...
ASKER
Thank you Idle_Mind! Your solution is better than what I've found!
ASKER
I have found a way to achieve it (not best, it works though):
In the class Form:
//************************
//** Win32 method imports to disable CloseBxo on title bar
//************************
[System.Runtime.InteropSer
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[System.Runtime.InteropSer
private static extern int DeleteMenu( IntPtr hMenu, uint uiPosition, uint uiFlags );
[System.Runtime.InteropSer
private static extern int DrawMenuBar(IntPtr hWnd)
private const int _iSC_CLOSE = 0XF060;
private const int _iMF_GRAYED = 0x0;
In Form_Load Method:
private void Form_Load(object sender, EventArgs e)
{
// Disable the CloseBox on the title bar
DeleteMenu(GetSystemMenu(t
DrawMenuBar(this.Handle);
}
The code above makes the Cloase Box on the applicatrion title bar disabled. That’s all.
One thing is strange to me that I tried using Win32 EnableMenuItem function and it doesn’t work for my purpose.
Thank you,
XWL