c# - MdiLayout.TileVertical 无法正常工作
问题描述
我曾在 C# 中使用 MDI 表单来显示多窗口。当我使用 MdiLayout.TileVertical 更改子窗口的布局时,我无法获得正确的结果。子窗口没有垂直显示。
我想要结果:
1
2
3
4
我得到了什么:
3 1
4 2
我的代码源:
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItemNew_Click(object sender, System.EventArgs e)
{
oFileDlg.CheckFileExists=true;
oFileDlg.CheckPathExists=true;
oFileDlg.Title="Open File - MDI Sample";
oFileDlg.ValidateNames=true;
oFileDlg.Filter = "jpg files (*.jpg)|*.jpg";
if (oFileDlg.ShowDialog() == DialogResult.OK)
{
try
{
//Create a new instance of the MDI child template form
Form2 chForm = new Form2();
//set parent form for the child window
chForm.MdiParent=this;
//increment the child form count
count ++;
//set the title of the child window.
chForm.Text= "Child - " + count.ToString();
chForm.fileloc=oFileDlg.FileName;
chForm.FormBorderStyle = FormBorderStyle.Sizable;
//display the child window
chForm.Show();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void menuItemClose_Click(object sender, System.EventArgs e)
{
//Gets the currently active MDI child window.
//Form a = this.ActiveMdiChild;
//Close the MDI child window
//a.Close();
this.Close();
}
private void menuItemAI_Click(object sender, System.EventArgs e)
{
//Arrange MDI child icons within the client region of the MDI parent form.
this.LayoutMdi(System.Windows.Forms.MdiLayout.ArrangeIcons);
}
private void menuItemCas_Click(object sender, System.EventArgs e)
{
//Cascade all child forms.
this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade);
}
private void menuItemHoriz_Click(object sender, System.EventArgs e)
{
//Tile all child forms horizontally.
this.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal);
}
private void menuItemVert_Click(object sender, System.EventArgs e)
{
//Tile all child forms vertically.
//CheckWindows();
this.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical);
}
private void menuItemMax_Click(object sender, System.EventArgs e)
{
//Gets forms that represent the MDI child forms
//that are parented to this form in an array
Form [] charr= this.MdiChildren;
//for each child form set the window state to Maximized
foreach (Form chform in charr)
chform.WindowState=FormWindowState.Maximized;
}
private void menuItemMin_Click(object sender, System.EventArgs e)
{
//Gets forms that represent the MDI child forms
//that are parented to this form in an array
Form [] charr= this.MdiChildren;
//for each child form set the window state to Minimized
foreach (Form chform in charr)
chform.WindowState=FormWindowState.Minimized;
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
//Gets forms that represent the MDI child forms
//that are parented to this form in an array
Form [] charr= this.MdiChildren;
//for each child form set the window state to Minimized
foreach (Form chform in charr)
chform.Close();
}
对这个问题有什么想法吗?
解决方案
您可以尝试在子窗体上做对接,并选择所需的输出。
例如:chForm.Dock = DockStyle.Left;
推荐阅读
- angular - 从 AngularJS 升级到 Angular 8 在从 ng-repeat 中使用的 ng-include 迁移时遇到问题
- javascript - 如何在不重新渲染的情况下使用 React Router 向 url 添加哈希?
- .net-core - 将 Include 与 EF Core 一起使用时,导航属性始终为空
- blazor - 如何从 blazor 服务器端下载文件
- git - git 挂起通过 ssh 执行远程命令
- javascript - 在 JSP 页面中扫描二维码时如何进行 POST
- python-3.x - 如何避免对不平衡数据的过度拟合?
- c# - 如何导入 System.Net.Http.ObjectContent