![](/img/trans.png)
[英]How to show a child form within a mdi container form which its windowstate= maximized?
[英]mdi child form maximized windowstate - BorderStyle
我想在父窗口中打开一个子窗体,最大化窗口状态。
我不想让用户最小化/最大化/关闭该子窗口,
所以我为childwindow设置BorderStyle = None
,并将MaximizeBox
和MinimizeBox
属性设置为False
,同时设置WindowState = Maximized
但是当我运行该程序时,它会以最大化状态显示该childForm的所有Minimize
, Restore
和Close
按钮。
但如果我单击Restore Down
然后没有该childForm的边框..现在无法将其恢复到最大化状态..
我错过了什么吗? 这是一个错误吗? 使其正常工作的正确方法是什么?
试试吧。
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);
}
那么你可以创建自己的表单(客户表单),然后将该自定义表单继承为mdi子表单
你必须将以下代码放在“自定义表单”中
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);
}
}
您必须并且应该将您的mdi子表单minimum size to '0'
并将size to Width = 806; Height = 730;
size to Width = 806; Height = 730;
我希望它会帮助你......
不要将其设置为最大化,只需设置MdiParent的宽度和高度......
Height = this.Height;
Width = this.Width;
this.Width应该是父表单
希望这有帮助,如果没有。 给我发电子邮件:)
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.