I need help passing input in Form2.textbox1 to Form1.sti
Form1 = Main working window
Form2 = Popup window, to enter path.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
public string sti { get; set; }
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = sti;
this.Close();
}
}
public partial class Form1 : Form
{
int CountR = 1;
public Form1()
{
InitializeComponent();
}
public string sti { get; set; }
public void Form1_Load(object sender, EventArgs e)
{
Form2 popup = new Form2();
popup.ShowDialog();
popup.Dispose();
}
public void button1_Click(object sender, EventArgs e)
{
Label7.Text = sti;
}
But it always returns Null.
I’ve builded it this way because I don’t want user to mess with the path only IT administrators.
Thank you in advance
You are creating a new.Form1that does not have a reference to theForm2that you createdYou changed your example, you have created 2 different sti properties, you need to assign the
Form2sti value to the property inForm1before you close Form2.This code should work for you.
Form1
Form2
You can also create a static class that can be referenced from both forms, that way you are dealing with only one sti property. Something like this:
Form1
Form2