locked
Transfering Text in Textbox into Textbox in Another Form RRS feed

  • Question

  • hi all, I absolutely new in C#.net but I have knowledge in VB.net, I have 2 Form in my Project and each form have textbox, in Form1, Textbox name is TextBox1 and In Form2 textbox name is TextBox2. I Trying to transfer Textbox1 in Form1 into Textbox2 Form2, I already tried with this code:

    // Code in Form1:
    
            public TextBox filename
            {
                get
                {
                    return TextBox1;
                }
            }
    
    // Code in Form2:
            private Form1 MainForm;
            public void gettext
            {
               Textbox2.Text = MainForm.filename.Text;
            }

    But its throwing the exception:

    "Object reference not set to an instance of an object."

    Please help me, Thanks!


    • Edited by ChronO2Jam Friday, February 10, 2012 2:05 PM
    • Moved by CoolDadTx Friday, February 10, 2012 2:42 PM Winforms related (From:Visual C# General)
    Friday, February 10, 2012 2:03 PM

Answers

  • please  pass the instance of form1 in the Form2's load event

      private void Form2_Load(object sender, EventArgs e)
            {
             this.MainForm=instance of Form1;       

    }


    Well I already fix it with myself, Thanks for your time ^^"
    • Marked as answer by ChronO2Jam Saturday, February 11, 2012 2:27 PM
    Saturday, February 11, 2012 2:27 PM

All replies

  • please  pass the instance of form1 in the Form2's load event

      private void Form2_Load(object sender, EventArgs e)
            {
             this.MainForm=instance of Form1;       

    }


    • Edited by Jacky_shen Friday, February 10, 2012 2:21 PM
    Friday, February 10, 2012 2:18 PM
  • please  pass the instance of form1 in the Form2's load event

      private void Form2_Load(object sender, EventArgs e)
            {
             this.MainForm=instance of Form1;       

    }


    Well I already fix it with myself, Thanks for your time ^^"
    • Marked as answer by ChronO2Jam Saturday, February 11, 2012 2:27 PM
    Saturday, February 11, 2012 2:27 PM