最大化MDI子窗体 [英] Maximize MDI child form
问题描述
我工作的一个传统的WinForms MDI应用程序,并有一些麻烦让孩子形式表现为我想。
我的目标是让子窗体的总是的最大化(对接)。
现在的问题是,即使我设置 MaximizeBox
到假
的最大化/调整大小按钮会出现在计量吸入器工具条,让用户调整大小(取消停靠)子窗体。
,来避免这种情况的唯一方法是设置控制盒
到假
但随后的关闭按钮消失,(那不是我想要的)。
我已经尝试使用固定 FormBorderStyle
并最大限度地儿当resize事件被触发,但没有我的方法工作形成。
有我错过任何超级秘密财产,或只是不可能?
最好的问候和放大器;在此先感谢
更新
我写了一个肮脏的方法(感谢@rfresia),用于处理孩子的形式,它可以帮助别人谁遇到同样的问题:
//所有子窗体从ChildForm
获得//父MDI窗体实现
// ...
私人无效ShowForm(ChildForm形式)
{
//检查形式的一个实例,如果已经存在
( Forms.Any(X => x.GetType()== form.GetType()))
{
变种F = Forms.First(X => x.GetType()==形式.GetType());
f.Focus();
f.WindowState = FormWindowState.Maximized;
}
,否则
{
//设置必要的属性(任何其他属性都设置为默认值)
form.MdiParent =这一点;
form.MaximizeBox = FALSE;
form.MinimizeBox = FALSE;
form.WindowState = FormWindowState.Maximized;
Forms.Add(表);
form.Forms =形式;
form.Show();
form.Focus();
//让我们让它讨厌的(有些形式不正确渲染,否则)
form.WindowState = FormWindowState.Normal;
form.WindowState = FormWindowState.Maximized;
}
}
// ...
// ChildForm执行
// ...
公开名单<表格及GT;表格{搞定;组; }
保护覆盖无效OnClosing(System.ComponentModel.CancelEventArgs E)
{
Forms.RemoveAll(X => x.GetType()==的GetType());
}
保护覆盖无效onResize受到(EventArgs的发送)
{
的WindowState = FormWindowState.Maximized;
}
您可以覆盖的onResize受到每个孩子形成要确保不减少。或创建一个基本形式,并继承所有的孩子从它的形式。
保护覆盖无效onResize受到(EventArgs的发送)
{
this.WindowState = FormWindowState.Maximized;
}
此外,您还可以使用X,Y坐标,但是onResize受到应该够了。把这个子窗体的构造函数:
this.WindowState = FormWindowState.Maximized;
点NewLoc = Screen.FromControl(本).WorkingArea.Location;
// Modifiy的位置,以便任何工具栏和放大器;任务栏可以方便地访问。
NewLoc.X + = 1;
NewLoc.Y + = 1;
this.Location = NewLoc;
规格= NewSize Screen.FromControl(本).WorkingArea.Size;
// Modifiy大小,以便任何工具栏和放大器;任务栏可以方便地访问。
NewSize.Height - = 1;
NewSize.Width - = 1;
this.Size = NewSize;
this.MinimumSize = this.Size;
this.MaximumSize = this.MinimumSize;
我对X代码,Y从这里开始:
的http://bytes.com/topic/c-sharp/answers/278649-how -DO-I-防止外形调整
I'm working on a legacy WinForms MDI application and have some trouble making the child forms behave as I want. My objective is to have the child form always maximized (docked).
The problem is, that even if I set MaximizeBox
to false
the maximize/resize button appears in the MDIs toolstrip and let the user resize (undock) the child form.
The only way to avoid this is to set ControlBox
to false
but then the close button disappears to (thats not what I want).
I've already tried to use a fixed FormBorderStyle
and to maximize the child form when the resize event is fired but none of my approaches worked.
Is there any super secret property I have missed or is it just impossible?
Best Regards & Thanks in advance
Update
I wrote a sleazy method (thanks to @rfresia) for handling my child form, it may help others who run into the same issue:
//All child forms derive from ChildForm
//Parent MDI Form implementation
//...
private void ShowForm(ChildForm form)
{
//Check if an instance of the form already exists
if (Forms.Any(x => x.GetType() == form.GetType()))
{
var f = Forms.First(x => x.GetType() == form.GetType());
f.Focus();
f.WindowState = FormWindowState.Maximized;
}
else
{
//Set the necessary properties (any other properties are set to default values)
form.MdiParent = this;
form.MaximizeBox = false;
form.MinimizeBox = false;
form.WindowState = FormWindowState.Maximized;
Forms.Add(form);
form.Forms = Forms;
form.Show();
form.Focus();
//Lets make it nasty (some forms aren't rendered properly otherwise)
form.WindowState = FormWindowState.Normal;
form.WindowState = FormWindowState.Maximized;
}
}
//...
//ChildForm implementation
//...
public List<Form> Forms { get; set; }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
Forms.RemoveAll(x => x.GetType() == GetType());
}
protected override void OnResize(EventArgs e)
{
WindowState = FormWindowState.Maximized;
}
You can override the OnResize of each child form you want to make sure does not minimize. Or create a BaseForm and inherit all children forms from it.
protected override void OnResize(EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
Also, you can use X,y coordinates, but OnResize should be enough. Put this in the child form constructor:
this.WindowState = FormWindowState.Maximized;
Point NewLoc = Screen.FromControl(this).WorkingArea.Location;
//Modifiy the location so any toolbars & taskbar can be easily accessed.
NewLoc.X += 1;
NewLoc.Y += 1;
this.Location = NewLoc;
Size NewSize = Screen.FromControl(this).WorkingArea.Size;
//Modifiy the size so any toolbars & taskbar can be easily accessed.
NewSize.Height -= 1;
NewSize.Width -= 1;
this.Size = NewSize;
this.MinimumSize = this.Size;
this.MaximumSize = this.MinimumSize;
I got the code for the X,Y from here: http://bytes.com/topic/c-sharp/answers/278649-how-do-i-prevent-form-resizing
这篇关于最大化MDI子窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!