简体   繁体   English

mdi子窗体最大化windowstate - BorderStyle

[英]mdi child form maximized windowstate - BorderStyle

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 所以我为childwindow设置BorderStyle = None ,并将MaximizeBoxMinimizeBox属性设置为False ,同时设置WindowState = Maximized

But when I run the program it shows all Minimize , Restore and Close buttons for that childForm in maximized state. 但是当我运行该程序时,它会以最大化状态显示该childForm的所有MinimizeRestoreClose按钮。

but if I click Restore Down then there is no border for that childForm..now No way to restore it to maximized state also.. 但如果我单击Restore Down然后没有该childForm的边框..现在无法将其恢复到最大化状态..

Am I missing something? 我错过了什么吗? Is this a bug? 这是一个错误吗? What is the proper way of making it work correctly? 使其正常工作的正确方法是什么?

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);
}

Well you can create your own form(custome form) and then inherite that custom form into mdi child form 那么你可以创建自己的表单(客户表单),然后将该自定义表单继承为mdi子表单

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; 您必须并且应该将您的mdi子表单minimum size to '0'并将size to Width = 806; Height = 730; size to Width = 806; Height = 730;

I hope it will helps you... 我希望它会帮助你......

Dont set it to maximised, Just set the width and height of the MdiParent... 不要将其设置为最大化,只需设置MdiParent的宽度和高度......

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

this.Width should be the parent form this.Width应该是父表单

Hope this helps, If it does not. 希望这有帮助,如果没有。 Drop me an email :) 给我发电子邮件:)

beanlovin@gmail.com beanlovin@gmail.com

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM