c# - Reloading the form instead of making a new one / accessing textbox outside of form -


i having problem controlling textbox. need change value outside of form1.cs textbox located have found snippet.

public void updatetext(string newvalue) {     torrent_name0.text = newvalue; } 

this allows me in theory control textbox outside of form1.cs, here comes problem, every time want access create new instance of form1 instead of using old 1 , refreshing it.

form1 frm = new form1(); frm.updatetext("aaaaaaaaaaaa"); frm.show(); 

am missing something? there better way this? have tried multiple ways update new form got nowhere.

bokker,

you have have reference singular form1 things refer.

if child form, aybe commented, create public member of mainform , name something.

public form myform1; 

you have event form1 launched...

a button click, menu item, toolbar item, etc. in event have check if form exists , create if required.

private someevent() {   if (myform1 == null)       {       myform1 = new form1();       myform1.show(this);      }    myform1.updatetext("some text"); 

}

alternatively, create form in form load event, long create form prior attempting myform1.updatetext() if follow paradigm, creating myform1 part of main form, best practice says should dispose of form in main form closing event.

private void mainform_formclosing(object sender, formclosingeventargs e)   {      if (myform1 != null)         {          myform1.close();          myform1.dispose();         }   } 

this off top of head, might not perfect.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -