Help Hiding Maximize Button on Form

  • Thread starter Thread starter webbertsolutions
  • Start date Start date
W

webbertsolutions

I am trying to hide >> JUST << the Maximize button.
I want the Minimize and Close to still show up and work.

This is what I tried. The call to GetWindowLong() always
returns Zero as the value.

Thanks,
Dave


// ------------------------------------------

[DllImport("user32.dll")]
static extern long GetWindowLong(long hwnd, long nIndex);

[DllImport("user32.dll")]
static extern long SetWindowLong(long hwnd, long nIndex, long dwNewLong);

// ------------------------------------------

private void mainForm_Load(object sender, System.EventArgs e)
{
// Set up additional information
InitializeForm();
}

// ------------------------------------------
private void InitializeForm()
{
const int WS_MAXIMIZEBOX = 0x10000;
const long GWL_STYLE = -16;

long hWnd = this.Handle.ToInt32();
long style = GetWindowLong(hWnd, GWL_STYLE);

style = style & ~WS_MAXIMIZEBOX;
SetWindowLong(hWnd, GWL_STYLE, style);
this.Invalidate();
}

// ------------------------------------------
 
I am trying to hide >> JUST << the Maximize button.
I want the Minimize and Close to still show up and work.

There is no way to hide the button, but you can disable it by setting the
form's 'MaximizeBox' property to 'False'.
 
Back
Top