I need to pass a string that from my first UserControl to the second UserControl. How do i do?
You can define custom property to achieve it.
First, define property UC2
in Form1.cs
to access the SecondUC instance
.
public SecondUC UC2
{
get { return secondUC1; }
set { secondUC1 = value; }
}
Then, define property TB2
in SecondUC.cs
to access the TextBox instance
that in SecondUC
.
public TextBox TB2
{
get { return textBox2; }
set { textBox2 = value; }
}
Last, set the TextBox2
vaule by clicking button in FirstUC
.
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = (Form1)this.FindForm();
form1.UC2.TB2.Text = "test string";
}
Test result,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.