c# - Class to store data -


i'm writing program in c# , have little problem passing variable between 2 forms. example in form1 have got textbox put data , need show in textbox in form2. tried make additional class properties "get,set" doesn't work, don't know why.

code form1

private void button1_click(object sender, eventargs e)         {              danedelegacja dane = new danedelegacja();             dane.miejscedocelowe = textbox1.text;              // create new instance of form2 class             form2 settingsform = new form2();              // show settings form             settingsform.show();             this.hide();         } 

and code form2:

 public form2()         {             initializecomponent();             danedelegacja dane = new danedelegacja();             textbox1.text = dane.miejscedocelowe;          } 

class store data:

class danedelegacja     {         public  string miejscedocelowe { get; set; }     } 

that's not working because creating new instance every time in form2's constructor.

private void button1_click(object sender, eventargs e) {      danedelegacja dane = new danedelegacja();     dane.miejscedocelowe = textbox1.text;      // create new instance of form2 class     form2 settingsform = new form2(dane);      // show settings form     settingsform.show();     this.hide(); } 

and code in form2:

public form2(danedelegacja dane) {     initializecomponent();    // danedelegacja dane = new danedelegacja(); <-- remove line     textbox1.text = dane.miejscedocelowe; } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -