connectseekers.com

Sunday, 15 June 2014

Pass Value From One Form to Another Form in Windows Application C#.Net,VB.Net

6/15/2014 - By Pranav Singh 0

When we create a windows application on that case we always face the situation where we needed to pass the value from one form to the another form.

So in this article I will show you how you can pass value from one form to another form in windows application using c#.net and vb.net.


For this article first we will create a new windows application and add two form.  Form1 and from2 .

Form1 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 DemoWindowsApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 objform2 = new Form2();
            objform2.form1value = textBox1.Text;
            objform2.Show();
        }
    }
}

In above code we have declared a public variable in Form2 which is form1value. so we have passed the value of textbox to form1value.

Form2 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 DemoWindowsApplication
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public string form1value = "";
        private void Form2_Load(object sender, EventArgs e)
        {
            label2.Text = form1value;
        }
    }
}


Now here is the output


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top