airhalynn101
airhalynn101

Reputation: 81

Visual Basic 2010 Copy text from one textbox to another

I have two forms, and I want to get the value of textbox1 from form1 and display it as the value of textbox2 in form2. I also want the text in textbox2 to appear in textbox3 in the same form (form2), but when I run the program, the values don't show up on textbox3. I hope you're getting the logic because it's really confusing and I can't put it anymore simple. Here's the code I'm trying to do:

 'this is when i get the value of textbox1 from form1 to form2's textbox2
 'this part works, because textbox1's value gets displayed on textbox2
 Private Sub form1_FormClosing(ByVal sender As Object, ByVal e As _
 System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

     'i want to forward the values before form close
     form2.textbox2.Text = textbox1.Text

 End Sub

I want to get the value of textbox2 and display it on textbox3 (both are on the same form, form2), so I use

 textbox3.Text = textbox2.Text

However, the value doesn't get displayed on textbox3. This is where my problem is. I hope anyone could help me on what I should do here. I also hope you get it clear :(

EDIT: I have already solved this one by using a counter so that the value of textbox1 can be displayed directly on textbox3. Thank you guys :)

Upvotes: 0

Views: 4106

Answers (1)

Rahul
Rahul

Reputation: 77856

It won't make sense passing the variable in form closing.

Form2 constructor should accept a string value like

public Form2(string frm1_text)
{
    InitializeComponent ();
    this.textbox2.Text = frm1_text;
    this.textbox3.Text = frm1_text;
    }
}

Then pass the variable while calling/instantiating form2 like

Form2 frm = new Form2(textbox1.Text)

You can even try this, using properties as explained in below link

Getting a Value from Another Form (Visual C#)

Upvotes: 3

Related Questions