Windows Forms: How to Transfer Information between Forms in C#
By FoxLearn 7/18/2017 8:52:46 PM 5.03K
Transfer or Passing data between Forms in C#
Step 1: Click 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
Step 2: Design your form as below
Form1
Form2
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
- Windows Forms: How to make an Application auto run on Windows startup in C#
- Windows Forms: Wait Form Dialog in C#
- How to create a Lucky Draw games in C#
- Windows Forms: Youtube Search with Paging in C#
- Windows Forms: Text to speech in C#
- Windows Forms: Print Picture Box in C#
- Windows Forms: Advanced Filter DataGridView in C#
- Windows Forms: Progress Bar in C#
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024