Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.9k

Get value from another form in already opened form1

May 25 2018 4:18 AM
My code work...problem is ...
Form 1 button click open Form2 and find value, when return value open new form not existing? Some help
I think it is problem line 11..12...
 
  1. //form1:    
  2.  public partial class Form1 : Form    
  3.     {    
  4.         Form2 f2;    
  5.         public Form1()    
  6.         {    
  7.             InitializeComponent();    
  8.         }    
  9.         private void button1_Click(object sender, EventArgs e)    
  10.         {    
  11.             if (f2 == null)    
  12.                 f2 = new Form2();    
  13.             f2.ValueFromForm1(textBox1.Text);    
  14.             f2.Show();    
  15.         }    
  16.     }    
  17. //form2:    
  18.  public partial class Form2 : Form    
  19.     {    
  20.         public Form2()    
  21.         {    
  22.             InitializeComponent();    
  23.         }    
  24.         public void ValueFromForm1(string value)    
  25.         {    
  26.             textBox1.Text = value;    
  27.         }    
  28.     }   
 

Answers (3)