mdi child form maximized windowstate - BorderStyle

9.8k Views Asked by At

I want to open a child form inside parent with maximized windowstate.

I don't want to let the user minimize/ maximize/ close that child window,

so I set BorderStyle = None for childwindow and also set MaximizeBox and MinimizeBox properties to False, also set WindowState = Maximized

But when I run the program it shows all Minimize, Restore and Close buttons for that childForm in maximized state.

but if I click Restore Down then there is no border for that childForm..now No way to restore it to maximized state also..

Am I missing something? Is this a bug? What is the proper way of making it work correctly?

4

There are 4 best solutions below

0
On

Well you can create your own form(custome form) and then inherite that custom form into mdi child form

you have to place the below code in "custom Form"

   public partial class BaseForm : Form
   {
       public BaseForm()
       {
           InitializeComponent();
           StartPosition = FormStartPosition.WindowsDefaultLocation;
           MaximizeBox = false;
           Width = 806;
          //Width = 850;
          //Height = 760;
           Height = 730;
          //Width = 790;
          //Height = 617;
    }

//[DllImport("user32.dll")]
//[return: MarshalAs(UnmanagedType.Bool)]
//private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
//private enum ScrollBarDirection { SB_HORZ = 0, SB_VERT = 1, SB_CTL = 2, SB_BOTH = 3 } 


protected override void WndProc(ref Message m)
{
  const int WM_SYSCOMMAND = 0x0112;
  const int SC_MOVE = 0xF010;
  //ShowScrollBar(this.Handle, (int)ScrollBarDirection.SB_BOTH, false);
  switch (m.Msg)
  {
    case WM_SYSCOMMAND:
      int command = m.WParam.ToInt32() & 0xfff0;
      if (command == SC_MOVE)
        return;
      break;
   }
   base.WndProc(ref m);
 }
}

you must and should put your mdi child form minimum size to '0' and size to Width = 806; Height = 730;

I hope it will helps you...

1
On

Dont set it to maximised, Just set the width and height of the MdiParent...

Height = this.Height;
Width = this.Width;

this.Width should be the parent form

Hope this helps, If it does not. Drop me an email :)

[email protected]

0
On
Form1 fr = new Form1(); 
fr.MdiParent = this; //set form's parent to Mdiform
fr.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //set form without maximize,minimize and close button
fr.Dock = DockStyle.Fill; //set form's dock property to fill
fr.Show();
0
On

just try this one.

protected override void WndProc(ref Message m)
{
    const int WM_SYSCOMMAND = 0x0112;
    const int SC_MOVE = 0xf010;
    switch (m.Msg)
    {
        case WM_SYSCOMMAND:
            int command = m.WParam.ToInt32() & 0xfff0;
            if (command == SC_MOVE)
                return;
            break;

    }
    base.WndProc(ref m);
}