ramesh p

ramesh p

  • NA
  • 109
  • 0

How to show one form text box data in another form

Mar 23 2010 8:53 AM

I am working on c# windows application. I have 2 forms. Form1 has one textbox and one button. If you click on the form1 button it should be displayed form2. And Form 2 also having one button and one text box. In form2 we have to enter some text in the textbox and click the button. The text should be displayed in the form1 textbox. Both forms should be active. We have to refresh form1 textbox. How?

 

Here I am doing like this: but form1 textbox is not refreshing....

 

public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            if (PropNearest != string.Empty)

            {

                this.textBox1.Text = PropNearest;

            }

        }      

 

        public string PropNearest

        {

            get

            {

                return this.textBox1.Text;

            }

            set

            {

                this.textBox1.Text = value;

               

            }

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            Form2 f2 = new Form2();

            f2.Show();           

        }

    }

 

This is form2 code:

 

 

public partial class Form2 : Form

    {

    

        Form1 f1 = new Form1();

        public Form2()

        {         

          

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            f1.PropNearest = textBox1.Text;  

            f1.Refresh();           

        }     

    }

 


Answers (7)