假设主窗体为Form1,那么用户控件里可以用 Form1 f = this.FindForm() as Form1; f.textBox1.Text = "abc";前提是textBox1被设为public。
Form1.Designer.cs文件里有textBox1的定义,把private改为public
你先把usercontrol添加到窗体,在这里面处理usercontrol。 like this public partial class Form1 : Form { private void userControl11_Load(object sender, EventArgs e) { string str = this.textBox1.Text; } }
Form1 f = this.FindForm() as Form1;
f.textBox1.Text = "abc";前提是textBox1被设为public。
like this
public partial class Form1 : Form
{
private void userControl11_Load(object sender, EventArgs e)
{
string str = this.textBox1.Text;
}
}