954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pass the text box value from one form to another form textbox

I have teo form form1 and form2 i want to pass form1 textbox1 text in form2 textbox1.text whae i click a button of form1.(Its for windows application)

Plz give me some help......

vivekagrawal
Light Poster
41 posts since Mar 2011
Reputation Points: 7
Solved Threads: 0
 

You do:

//form1:
 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(textBox1.Text);
            f2.Show();
        }
    }

//form2:

    public partial class Form2 : Form
    {
        public Form2(string value)
        {
            InitializeComponent();
            textBox1.Text = value;
        }
    }
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

If you want to pass the value from form1 to form2 when the form2 is opened, you can use this kind of code:

//form1:
 public partial class Form1 : Form
    {
        Form2 f2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (f2 == null)
                f2 = new Form2();
            f2.ValueFromForm1(textBox1.Text);
            f2.Show();
        }
    }

//form2:
 public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void ValueFromForm1(string value)
        {
            textBox1.Text = value;
        }
    }
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

Mijja it it also work in which u hd solved my problem of dend doctor_id and name in another form,?????

vivekagrawal
Light Poster
41 posts since Mar 2011
Reputation Points: 7
Solved Threads: 0
 

Thanks mitja its working.........

vivekagrawal
Light Poster
41 posts since Mar 2011
Reputation Points: 7
Solved Threads: 0
 

Plz, make this thread has solved if u find ur answer.

Saikalyankumar
Junior Poster in Training
91 posts since Mar 2011
Reputation Points: 8
Solved Threads: 23
 

Man, again and again. One question for 2 weeks now. Please get some books and start learing by your self. We cannot teach you all here. We are here to help, not to teach ppl.
I wont answer on these kind of threads any longer. I think I gave given you more then enough, and if you still havent figured it out by now, this is not my problem. Sorry for sounding a bit harsh, but I simply dont like the way you are "forcing" us to do all the code you need instead of you.
bye

Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

I have 2 textbox in form 1 and have 2 ok button also...
When i write in my textbox1 in form1, the text will appear in textbox in form2, and when i write text in form 2 the text will appear in textbox1 in form1 or vise versa, Then when i write in textbox2 in my form1, the text appear in textbox in form 2 but when i edit the text that appear and press ok, it appear in textbox1 , my problem is i want to appear it in textbox2 not in textbox1...??HElp me please

moonleign
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: