I have 2 forms, for example FormA and FormB. In FormA I have 1 textBox, 2 numericupdowns and a button. In FormB i have listBox. I want to type something in textBox, select numbers and press the button on FormA, open FormB and in listBox to be the word i typed in FormA(textbox) and numbers I selected in numericUpDowns.
Asked
Active
Viewed 30 times
1 Answers
0
If you open the new form like this:
FormB form = new FormB(...);
you can access its properties and methods:
form.methodX();
With this knowledge, you can store an instance of FormB in a private variable in FormA and create a public method on FormB that will allow you to manipulate the contents of FormB.
public partial class FormA : Form
{
private FormB formb;
private void OpenFormB_Click(object sender, EventArgs e)
{
this.formb = new FormB();
formb.Show();
}
private void TextBox_TextChanged(object sender, EventArgs e)
{
this.formb?.UpdateList(...);
}
}

Mat Sz
- 2,524
- 1
- 10
- 23