c# - Public variable invoking incorrect result -


public partial class thanglishtotamilgui : form {     public string anz;      public thanglishtotamilgui()     {         initializecomponent();     }             public void btnconverttobraille_click(object sender, eventargs e)     {         anz = richtextboxtamil.text.tostring();          gui.tamiltobraillegui c1 = new gui.tamiltobraillegui();         c1.visible = true;                 }  } 

i need pass richtextbox (richtextboxtamil) content variable call anz.

i retrriving anz variable in other form form load event:

    private void tamiltobraillegui_load(object sender, eventargs e)     {         thanglishtotamilgui tt = new thanglishtotamilgui();         string apper = tt.anz;         richtextboxtamil.text = apper;     } 

my problem: getting null values result. since if assigned values invoked correctly.

public partial class thanglishtotamilgui : form {     public string anz = "hai";      public thanglishtotamilgui()     {         initializecomponent();     } ... 

here ans value passed "hai". requirement ever content in richtextboxtamil , pass public variable call anz. went wrong here please me.

thank you.

this problem:

thanglishtotamilgui tt = new thanglishtotamilgui(); string apper = tt.anz; 

how expect apper ever other null? you're fetching variable freshly-created form, has never been shown, , has never had btnconverttobraille_click called on it.

presumably there's existing thanglishtotamilgui object somewhere, , that's 1 want fetch variable from. basically, 1 form needs know instance of other form.

(i'd suggest using property rather public variable, that's different matter. might not need have separate variable @ - declare property fetches richtextboxtamil.text.)

alternatively, pass relevant string constructor of new form:

public void btnconverttobraille_click(object sender, eventargs e) {     gui.tamiltobraillegui c1 = new gui.tamiltobraillegui(richtextboxtamil.text);     c1.visible = true;             } 

then new form doesn't need know old form @ - only needs know text display.

(you might want pull out of constructor , settable property, it's same principle: code creating form pushes data, rather new form pulling it.)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -