C# winform 在一个窗体中如何设置另一个窗体的TextBox的值

如题所述

方法有很多,下拉给你列几个:
首先介绍最粗暴的方法,修改控件的访问修饰符。(不建议使用此法)
public System.Windows.Forms.TextBox textBox1;在调用时就能直接访问
Form1 frm = new Form1();
frm.textBox1.Text = "方法1";
frm.Show();
方法2是通过构造函数/指定公开方法传入,然后为对应控件赋值。
public Form2(string text)
{
InitializeComponent();
this.textBox1.Text = text;
}调用时
Form2 frm = new Form2("方法2");
frm.Show();
方法3是通过公开属性来设置,此法甚好。
public string Text3
{
get { return this.textBox1.Text; }
set { this.textBox1.Text = value; }
}调用如下
Form3 frm = new Form3();
frm.Text3 = "方法3";
frm.Show();等等,还有一些其他方法,这不一一介绍了。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答