In order to do this sort of thing, we must use the Windows API. Perry points us to a link to an
article, with an example written in VB:
http://www.dotnet4all.com/dotnet-code/2004/10/hiding-forms-close-controlbox-button.html
In order to test this, I converted it to C#.
[DllImport("user32")]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, int bRevert);
[DllImport("user32")]
public static extern int GetMenuItemCount(IntPtr hMenu);
[DllImport("user32")]
public static extern int DrawMenuBar(IntPtr hWnd);
[DllImport("user32")]
public static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
public const int MF_BYPOSITION = 0x400;
public const int MF_REMOVE = 0x1000;
public void DisableTheX(Form oForm)
{
IntPtr hMenu;
int n;
hMenu = GetSystemMenu(oForm.Handle, 0);
if (hMenu.Equals(IntPtr.Zero) == false)
{
n = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, n - 1, MF_BYPOSITION | MF_REMOVE);
RemoveMenu(hMenu, n - 2, MF_BYPOSITION | MF_REMOVE);
RemoveMenu(hMenu, n - 3, MF_BYPOSITION | MF_REMOVE);
DrawMenuBar(oForm.Handle);
}
}
from a solution provided by Perry Forman in Message #1099658
|