So I have two forms, and i want to pass a string value from opened form (Form2) to the main form (Form1)
The case is:
Show Form2 with a button in Form1, then Form2 shows a process list in a listbox. I want to pass the process name (string, with slctItm variable) from Form2 into a textBox in Form1 with a button in Form2. Please help me.
Code (form2):
...
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Process[] prc = Process.GetProcesses();
foreach ( Process aPrc in prc)
{
listBox1.Items.Add(aPrc.ProcessName);
}
}
private void button1_Click(object sender, EventArgs e)
{
string slctItm;
slctItm= listBox1.GetItemText(listBox1.SelectedItem);
//how to pass this value?
}
...
thanks