Sending a String From One Form To another Form C# -


this question has answer here:

i've been trying send string 1 form named mainform other form unlockform.

the references i've found sending values things textboxes. want send string.

this done in 2 ways. if trying pass string owner form child form, can in parameter, so:

class owner : form {    private child child;    public owner()    {        child = new child("value pass");    } } class child : form {      public child(string value)     {         //do value     } } 

if want pass child owner, this:

class owner : form {    public owner()    {        child = new child();        child.showdialog();        string childvalue = child.value;    } } class child : form {     public string value{get;set;}     public child()     {      }      protected override void onshown(eventargs e)     {         base.onshown(e);         value = "value set";         this.close();     } } 

note i'm using "child.showdialog()" make sure child form closed before value returns. isn't necessary, safer.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -