我在c#.now中的一个表单中有一个文本框,我想将此文本框标识为另一个表单,例如表单2。因为我想在下一个表单中使用该文本框。我该怎么办?
发布于 2013-10-10 00:02:39
如果您只关心Text属性,那么可以创建一个string属性,它将从该表单公开Text属性,而不是从表单中公开TextBox作为公共属性。
public string TextBoxText
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}如果要访问TextBox的其他属性,则必须在designer.cs文件中将其标记为public。
发布于 2013-10-10 00:03:29
您可以通过公开TextBox文本甚至TextBox控件的公共属性来公开它,而不是修改可能有害的designer.cs。下面的示例公开了Text属性。
Form1:
public string TextBoxABCText {
get { return YourTextBoxName.Text; }
set { YourTextBoxName.Text = value; }
}Form2:
Form1 frm1;
public Form2(Form1 frm1){
this.frm1 = frm1;
}
private void YourFunction(){
string strText = this.frm1.TextBoxABCText;
}https://stackoverflow.com/questions/19276943
复制相似问题