4

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?

techBeginner
  • 3,792
  • 11
  • 43
  • 59
  • 2
    This is just not the proper way to use MDI. It only gets in the way if you try to keep a child window maximized. Use a tabbed interface or swap UserControls to switch views. – Hans Passant Oct 22 '11 at 11:32
  • look at this link in stackoverflow may help you [How to disable the minimize button in C#?][1] [1]: http://stackoverflow.com/questions/319124/how-to-disable-the-minimize-button-in-c – DeveloperX Oct 22 '11 at 11:36
  • did you try dock panel? – pushpraj Jun 17 '14 at 12:23

4 Answers4

1

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);
}
Ry-
  • 218,210
  • 55
  • 464
  • 476
0

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

Glory Raj
  • 17,397
  • 27
  • 100
  • 203
0

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 :)

beanlovin@gmail.com

Bean
  • 1
  • `this.Height` and `this.Width` will set horizontal and vertical scrollbars because, child window should be smaller than parent window excluding the title bar and the borders.. – techBeginner Nov 01 '11 at 16:38
-1
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();
Chirag Shah
  • 464
  • 5
  • 9