Windows Forms: How to Transfer Information between Forms in C#

Transfer or Passing data between Forms in C#

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "TransferInformationExample" and then click OK

passing value to another form c#Step 2: Design your form as below

Form1

tranfer information between form in c#

Form2

transfer information between form in c#

Step 3: Add code to handle your windows forms as below

Form1

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

namespace TransferInformationExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnRetrieve_Click(object sender, EventArgs e)
        {
            //Open form 2, then retrieve value
            using(Form2 frm = new Form2())
            {
                if (frm.ShowDialog() == DialogResult.OK)
                    txtValue.Text = frm.GetValueInForm2;
            }
        }
    }
}

Form2

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

namespace TransferInformationExample
{
    public partial class Form2 : Form
    {
        //Get value from textbox
        public string GetValueInForm2
        {
            get
            {
                return txtValue.Text;
            }
        }

        public Form2()
        {
            InitializeComponent();
        }
    }
}

VIDEO TUTORIALS