|
hi,
how can i hide the exit, minimize and maximize buttons that appear on the top right side of the scree inside the title bar of the form. And if it is possible, also tell me how to modify the code and the action that those button do when clicked.
thanks in advance
jamil abou khalil
|
|
|
|
|
to remove. go to publishing Designer selects the form and change the property ControlBox to false.
to intercept.
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
protected override void WndProc(ref Message m)
{
if( m.Msg == WM_SYSCOMMAND)
{
if( (int) m.WParam.ToInt32() == SC_CLOSE )
{
if (ProjectIsOpen)
{
return;
}
else
{
this.Close();
Application.Exit();
}
}
}
base.WndProc (ref m);
}
|
|
|
|
|
hi,
first thanks for your reply. second i want to ask you a more detailed question. what if i want to hide only the close button and the maximize button and keep the minimize button. The property ControlBox when set to false hides the three buttons together even if i try to set the maximizebox to true it want appear.
i hope u have a solution for that.
jamil abou khalil
|
|
|
|
|
try it.
private const int SC_CLOSE = 0xF060;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_MINIMIZE = 0xF020;
private const int SC_RESTORE = 0xF120;
private const int MF_GRAYED = 0x1;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);
private void Disable_opt()
{
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_MAXIMIZE, MF_GRAYED);
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_MINIMIZE, MF_GRAYED);
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_RESTORE, MF_GRAYED);
}
|
|
|
|