I am creating a simple application in Visual Studio 2010 using C #, and I am doing this to get to know a user control, because it makes it easier to create multiple forms.
In the main form, there is a drop-down list containing 2 values, " UCType1" and " UCType2". I created two different user controls. I used the panel in the main form to display the user control according to what they selected in the drop-down list.
I was able to display the corresponding user control based on user selection, but now I am facing some kind of problem. I could not get the main form for reading data from a user control.
Let's say there is a button " Execute" and a label " Warning" in the main form. The user element has a text field " Name".
Scenario: when the user clicks " Execute", if " Name" is empty, " Warning" will display some error message.
I tried to use if(UserControl1.Name.Text == "")in the main form, but I could not even refer to it.
I know that I can simply create separate forms to simplify, as this will make the whole variable in one file, but I want to know if there is a way to do this with a user control, because I would like to familiarize myself with it.
thank
This is how I show my user control
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
UCType1 uc1 = new UCType1();
panel1.Controls.Clear();
panel1.Controls.Add(uc1);
}
and when I tried to display data from a user control
private void executeButton_Click(object sender, EventArgs e)
{
UCType1 uc1 = new UCType1();
warning.Text = uc1.Name;
}
nothing happened.