This article will demonstrate the different ways using which one can transfer values from one form to another. There are many possible ways of doing this but I have explained some of the simplest ones in this article.
1) Method 1 : Because VB.NET Creates all Objects as Public one can easily access the Components from another form without much complexity.
On the Load Event of the Form2 write the Following code
Label1.Text = Form1.TextBox1.Text
2) Method 2 : Creating Constructors in the Form2
Public Sub New(ByVal value As String)
Label1.Text = value
And Creating the Object of Form2 from Form1 using the following code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim f As New Form2(TextBox1.Text)
3) Method 3 : Using the Application.OpenForms - Forms Collection
In the Load Event of the Form2 use the Following Code
' This will Call the Instance of the Open form on the zero index.
Dim f As Form1 = Application.OpenForms(0)
Label1.Text = f.TextBox1.Text
B. C#. The techniques are little different in C# the First Method in VB.NET will not work in C#.
1. Method 1 : Create a Public Method in Form2 and Pass the value to the Method from Form1
public void SetValue(string value)
Form 1:- Create an Instance of Form2 and Call the Public Method
Form2 f = new Form2();
2. Method 2 : Creating Constructors in the Form2
public Form2(string value)
label1.Text = value;
private void button2_Click(object sender, EventArgs e)
Form2 f = new Form2(textBox1.Text);
3. Method 3 : Using the Application.OpenForms - Forms Collections
In the Load Event of the Form2 write the Following code
Form1 f = (Form1)Application.OpenForms;
label1.Text = f.TextBoxValue;
These are few techniques which can be used while transfering values from one Form to another.