Switiching Data between Forms in C#/VB.NET Windows Applications

I am going to explain how you can find the value of controls of one form in other forms.

While working in .NET windows application many times we want some data of one form int another form. So many times we have to search  a lot for these kind of issues. I am going to provide you the Full code for the same . Just download the project from the given links below and enjoy the coding.
Here is the code snipes for the same . Suppose we have two form Form1 and Form2 and there is a textbox named as TextBox1 on Form1 and Textbox2 on Form2 and we want the value of TextBox1 of Form1 in Textbox2 of Form2 . So onclick of a button or any event you want in Form1 just write the below code.


Download the corresponding languages code from the below links and share your thoughts.

VB.NET

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FRM2 As New Form2()
Me.Hide()
FRM2.TextBox1.Text = Me.TextBox1.Text
FRM2.ShowDialog()
End Sub



 
C#

private void Button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form2 FRM2 = new Form2();
            FRM2.TextBox1.Text = this.TextBox1.Text;
            FRM2.ShowDialog();
        }


Comments

Popular Posts