Size option disable from the system menu in c# application

816 Views Asked by At

I have a c# windows base application.Now I want that the in the system menu the size option should be disable.

To add the option in system menu I am using user32.dll. I am using windows form.

enter image description here

2

There are 2 best solutions below

2
On

If you have a dialog box (you haven't specified that) ...

... and if you're using Winforms (you haven't specified that, either) ...

then you can disable the ability to resize by specifying a Fixed border type; and y7ou can disable the ability to minimize or maximize by setting the respective form properties to "false".

For example:

form1.FormBorderStyle = FormBorderStyle.FixedDialog;
form1.MaximizeBox = false;
form1.MinimizeBox = false;

Otherwise, please specify what you're doing, and how you're trying to do it. Sample code is always helpful :)

0
On

Now I found the solution,

 private const int WM_SYSCOMMAND = 0x112;
 private const int MF_BYCOMMAND = 0x00000000;
 private const int SC_SIZE = 0xF000 ;
[DllImport("user32.dll")]
        private static extern int GetSystemMenu(int hwnd, int bRevert);
[DllImport("user32.dll")]
        private static extern bool DeleteMenu(int hMenu, int uPosition, int uFlags);

int menu = GetSystemMenu(this.Handle.ToInt32(), 0);
DeleteMenu(menu, SC_SIZE, MF_BYCOMMAND);