Click here to Skip to main content
14,733,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 to pass my richtextbox (richTextBoxTamil) content to variable call anz.
I am retrriving anz variable in other form as form load event:
private void TamilToBrailleGUI_Load(object sender, EventArgs e)
    {
        ThanglishToTamilGUI tt = new ThanglishToTamilGUI();
        String apper = tt.anz;
        richTextBoxTamil.Text = apper;
    }

My Problem: I am getting null values as result. Since if I assigned any values that invoked correctly.
public partial class ThanglishToTamilGUI : Form
{
    public string anz = "Hai";

    public ThanglishToTamilGUI()
    {
        InitializeComponent();
    } ...

Here my ans value is passed as "Hai". But my requirement is to get what ever the content in the richTextBoxTamil and pass it to that public variable call anz. What went wrong here please help me.

Thank you.
Posted
Comments
[no name] 14-May-13 9:34am
   
If I understand you correctly, and that is a big if, you want tt.anz = richTextBoxTamil.Text. But I doubt that will help you since you are creating a new instance of ThanglishToTamilGUI, changing the variable and then it goes out of scope and is destroyed.
Suthan-S 3-Jun-13 5:20am
   
Solution that i found is use of constructer.

Try by changing to static variable

public string anz;

as
public static string anz;
   
You will. The clue is in the word new:
ThanglishToTamilGUI tt = new ThanglishToTamilGUI();
String apper = tt.anz;

Since you create a new instance, it will not have the values that the user entered into a different instance!

Try just using the current value! Have a look at this: Transferring information between two forms, Part 1: Parent to Child[^]
(It may be you need one of the other tips in the series - I can't see your code so I can't tell)
   
Comments
Suthan-S 14-May-13 10:20am
   
Thank you. Really helpful. :)
OriginalGriff 14-May-13 10:27am
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900