Category       
  Server Script
  Client Script
  Data Base
  HTML - CSS
  Third Party
  Mobile Development
  Other
 
 Articles Detail
Posted Date : 10/20/2012     No Of Visit : 4479
Introduction : In this article i will show you how you can pass value from one form to another windows form to another windows Form.
Other Related Tag
 
In this article i will show you how you can pass value from one form to another windows form to another windows Form. At the end of the article you will learn to pass value as we pass value in asp.net by using session , request query string.

For this first you needed to create a windows project and add two windows form. In form one add a text box and button and in second form add a label as shown below.

Form1:



Form2:




Now open the form2 and create a public variable.


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 Form_Value_passing
{
    public partial class Form2 : Form
    {
        public string _valueOfForm1 = "";
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            lblvalue.Text = _valueOfForm1;
        }
    }
}

Check the bold text in above code.

Now cone to form1 and double click on button control to generate the button click event.  Now on button click add below code.

 
Form2 objForm2 = new Form2();
objForm2._valueOfForm1 = txtvalue.Text;
objForm2.Show();
this.Hide();
Now just check the bold section in the code. You are looking that the _valueOfForm1 is the variable which we have declared at form2.
(Note :In above code first we have assigned the to public variable and then show the form2 and at last hide to form1.)
Just check the below image


Now run the application and add some text after adding text click on button. Form2 will open and you will get the value form1 text box value at form2.



In above you are assigning the collected value to label. Now check the output.



click on button and your output.



________________________________________________________________________

DOWNLOAD


________________________________________________________________________

 You May Also Like This
 blue arrow  Query For Random Record Display In MS SQL
 blue arrow  File Upload in MVC3 By Using Razor
 blue arrow  Code To Insert, Update, Delete Record In Sql Server DataBase Using Asp.net (or) Perform Insert, Update,Delete Using Asp.net In C#
 blue arrow  Jquery Mobile Fancy Swithch On Off Effect Example
 blue arrow  Code To Pass Value From One Windows Form To Another Windows Form In Windows Form Using C#
 blue arrow  Facebook like Twitter Follow us Box Widget with Count Plugin Using jQuery
 blue arrow  AJAX CalendarExtender Disable PastDate Selection
 blue arrow  Enable/Disable Button On Selection Of RadioButtonList Using Jquery In Asp.Net
 blue arrow  Jquery Code To Disable DropDownList Item in Asp.Net
 blue arrow  Binding GridView Using C# in Asp.Net
 blue arrow  Asp.Net Code To Focus on the Control When Validator Control Fires
 blue arrow  Code for Catching an Exception C#.Net
 blue arrow  Dynamically Enable or Disable Validator and Page.IsValid Using C# In ASP.NET
 blue arrow  SortedList Class Example For Shorting A List In C#.Net
 blue arrow  Code To Display Rows as Columns in Gridview in Asp.net Using C#
 User Profile
Name : Vinay Singh
Company Name : -
Blog Name : -
About Me:
 User Comments       
Name : (max 50)
Your Comment : (max 800)
Posted By :parth Posted Date :12/14/2012
 
but i used one combo box and one textbox so how to pass their value at same time to other page?
 
Posted By :vinay Posted Date :12/15/2012
 
Hi path as i have shown in my code to pass the textbox value from one form to another form. So for passing the two control value just declare two global variable in the form where you want to access the value Eg: On form2 public string _textboxvalue=""; public int _conboboxvalue=0; On form1 for passing the value use the way which is defined in the article
 
Posted By :Abhishek Posted Date :12/30/2012
 
How to pass a value from form1 to form2 and then add both string
 
Posted By :vinay Posted Date :12/31/2012
 
Hi Abhishek, according my understanding of your question "you want to append some string with the value which u r getting on form2. so for this you can do one thing just user "THE VARIABLE IN WHICH YOU HAVE PASSED THE VALUE FROM FORM1 WRITE IT IN THIS WAY ---lblval.Text=_valuefromform1+"your test";----
 
Posted By :theYoungNoob Posted Date :1/27/2013
 
hi Vinay, I thank You!!! more tuts to come :))
 
Posted By :Bogdan Posted Date :4/6/2013
 
Thank you for code. It is very helpful. Finally I have got out from deadlock!
 
Email Id
Password
Forgot Password   |   New Registration
;