Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

C# textbox sending text value. Situation, i got 2 forms. Form1 and Form2. Form1 got a textbox and form2 got a textbox and a button, i will put a text value on form2 textbox and when i click the form2 button the value of form2 textbox will be sent and change the form1 textbox value....Need help..

This is what ive done..im just gonna summarize it

Form1 got no codes just textbox1

This is the code in form2 button

  private void change_Click(object sender, EventArgs e)
        {
         form1 frm1 = new form();
         string test = textbox2.text
         frm1.textbox.text = test;



}

ive try some poping message box to check if the value pass...and so far the value was really pass but no changes in the UI

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
929 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming you create Form2 as a child of Form1 (from within Form1, do something like Form2 from = new Form2();, you can access any public property of the child form from within the parent. So, just make sure to set the accessibility of the TextBox to public, and do something like this:

var form = new Form2();
form.ShowDialog();
this.TextBox1.Text = form.TextBox1.Text;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...