在 MDI 中从另一个子窗口打开子窗口
我在使用 Windows 窗体开发 MDI 应用程序期间遇到一些问题。
想象一下具有 3 个表单的小型测试应用程序:Form1、Form2 和 Form3。 Form1 是一个 MdiContainer(带有带有单个按钮的附加 menuStrip 元素 - 用于测试目的)。 Form2 仅包含单个按钮。单击 Form1 菜单条按钮即可打开 Form2。 Form3 应通过单击 Form2 按钮打开。
我已经使用谷歌解决了这个问题,但没有任何帮助。
我的代码如下:
Form1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void menu2ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 chWin = new Form2();
chWin.MdiParent = this;
chWin.Show();
}
}
Form2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();
form3.Show();
}
}
Form3 实际上根本没有代码。
很明显,我已经以某种方式声明 Form3 应该是 Form1 子级,但是如何声明呢? :)
提前致谢!
I have some problems during MDI application development using Windows Forms.
Imagine small test application with 3 forms: Form1, Form2 and Form3.
Form1 is an MdiContainer (with attached menuStrip element with single botton - for test purposes).
Form2 contains only single button. Form2 openes by the click on Form1 menuStrip button.
Form3 should open by Form2 button click.
I've already used google for this trouble, but nothing helpful.
My code is below:
Form1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void menu2ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 chWin = new Form2();
chWin.MdiParent = this;
chWin.Show();
}
}
Form2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();
form3.Show();
}
}
Form3 actually has no code at all.
It is quite obvious that I have somehow declare that Form3 should be Form1 child but how? :)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置 Form.MdiParent 属性表单3:
Set the Form.MdiParent property on
form3
:form3.MdiParent = this.MdiParent
form3.MdiParent = this.MdiParent