How to pass value from one form to another form

How to pass value from one form to another form


How to pass value from one form to another form using windows applicaiton.
Step 1:-
Click File-->New-->Project then click new project window will display
and choose or c# then give name to it.

Step 2:-
Right click the project name and click Add -->Windows form

Step 3:-

In Form 1 just drag and drop one button and textbox control.In button click event just create the object for form2.

Step 4:-
Just drag and drop one textbox control to show the form1 textbox value and click the textbox then go to the property window change the property of modifiers to public(Default is private).

Take the below code and check it.

C# Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
public partial class Form1 : Form
public Form1()

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

VB.Net Code

Public Class Form1

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


Author: Aman Gandhi17 Feb 2011 Member Level: Gold   Points : 1

but what if i want to transfer value using a string. i just want to store that value on another form.

how to do that.

Guest Author: gaurav03 Sep 2012

then you should make a function on another form like getvaluefromform1(string value); and call it on form 1
form2 frm=new form2();
frm.getvaluefromform1("hi i am gaurav");;

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: