问题--Form1窗体我设置为MDI窗口容器,Form2窗体为子窗体,在Form2窗体中有个TextBox控件,如何在Form1父窗体中调用Form2子窗体的控件?也就是怎么传递数据?我是写个文本编辑器小软件遇到的问题!把Form2子窗体的TextBox控件的Multiline属性设置成多行,在利用Form1父窗体的对话框组建打开一个TXT文件,把TXT文件里面的内容显示传递到Form2子窗体的TextBox控件中,改怎么做?求例子。。好的教程。要详细滴。。感谢了。偶们是新手。只说理论,不太好理解。希望大家加群多交流下多知道我们这些新手支持的拿砖头砸。。7762922
一是在当前选中的子窗体打开
Form Frm = this.ActiveMdiChild; //获取当前活动子窗体
((TextBox)Frm.Controls["textBox1"]).Text = "文件内容";二是打开时新建一个子窗体
先获取文件路径,再新建子窗体,这时将文件路径以构造参数传过去,在子窗体中打开文件并显示~~~养成结帖的习惯~~~~~~
MDI窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1(textBox1.Text);
frm.Show();
}
}
}子窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(string s)
: this()
{
textBox1.Text = s;
}
}
}