我有一个MDIChild
表单,称为从表单和表单form1
继承的普通表单,该工具栏顶部有一个工具栏顶部有一个新建按钮,当我单击新按钮时,它会在父表单内加载工具栏下方MDIChild
MDIParent
MDIParent
form
Form1
TextBox
里面有一个form1
,当我点击保存按钮时,TextBox
应该MessageBox
通过调用它的函数来显示它的值,
但问题是我无法访问该TextBox
Text
物业?
我的 MDIParent 表单代码是
public partial class MDIParent1 : Form
{
// private int childFormNumber = 0;
MdiClient mdi = null;
string fname;
public MDIParent1()
{
InitializeComponent();
foreach (Control c in this.Controls)
{
if (c is MdiClient)
{
mdi = (MdiClient)c;
break;
}
}
}
private void load_form(object form)
{
foreach (Form f in mdi.MdiChildren)
{
f.Close();
}
if (form == null)
return;
((Form)form).MdiParent = this;
((Form)form).Show();
((Form)form).AutoScroll = true;
fname = ((Form)form).Name;
}
private void newToolStripButton_Click(object sender, EventArgs e)
{
load_form(new Form1());
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
if (fname == "Form1")
{
Form1 f1 = new Form1();
f1.show_message();
}
}
在我的 form1 代码是
public void show_message()
{
MessageBox.Show(textBox1.Text);
}
我的 MDIChild 表单代码是
public mdichild()
{
InitializeComponent();
this.Load += new EventHandler(this.mdichild_Load);
}
private void mdichild_Load(object sender, EventArgs e)
{
this.ControlBox = false;
this.WindowState = FormWindowState.Maximized;
this.BringToFront();
int h = Screen.PrimaryScreen.Bounds.Height;
int w = Screen.PrimaryScreen.Bounds.Width;
this.MinimumSize = new Size(w, h);
}
谁能帮我?