Help Hiding Maximize Button on Form

  • Thread starter webbertsolutions
  • 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();
}

// ------------------------------------------
 
H

Herfried K. Wagner [MVP]

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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top