Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

C - Sharp - Pass Data From One Window Form To Another Window Form Application

This document describes how to pass data between two forms in a C# Windows Forms application. It involves designing two forms with labels and textboxes, storing user-entered text from the textboxes in Form1 into public static variables, and then displaying that stored text on labels in Form2. The data is passed between forms by instantiating Form2 from Form1 and setting the label texts in Form2 to the static variables declared in Form1.

Uploaded by

ló Menekülő
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

C - Sharp - Pass Data From One Window Form To Another Window Form Application

This document describes how to pass data between two forms in a C# Windows Forms application. It involves designing two forms with labels and textboxes, storing user-entered text from the textboxes in Form1 into public static variables, and then displaying that stored text on labels in Form2. The data is passed between forms by instantiating Form2 from Form1 and setting the label texts in Form2 to the static variables declared in Form1.

Uploaded by

ló Menekülő
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Pass Data From One Window Form To Another Window Form

Application Using C#

We take some data from user in form 1 and display that data in form 2.

Initial chamber

Step 1: Open Visual Studio 2010, Go to File, New, Projects, then under Visual
C# select Windows.

You can change the name of the project and browse your project to different location too.
And then press – OK.

Design chamber

Step 2: Now open your Form1.cs file, where we create our design for form 1, take three
labels, change its text to name, email, city and then take three textboxes and a button.
Here's the image.
Now add one more Form to your project by going to your
project- Right Click, Add New Item, then Window Form.

Make its design like the following image, here we have to


take label control only to show the data from form1.

Code chamber

Right Click on the blank part of Form1.cs and click View


Code. You will see you are entered in the code part of the
form. Write the following code for Form1.cs.

Form1.cs
1. using System;
2. using System.Collections.Generic;
3. using System.ComponentModel;
4. using System.Data;
5. using System.Drawing;
6. using System.Linq;
7. using System.Text;
8. using System.Windows.Forms;
9. namespace WindowsFormsApplication1
10. {
11. public partial class Form1: Form
12. {
13. public static string l1;
14. public static string l2;
15. public static string l3;
16. public Form1()
17. {
18. InitializeComponent();
19. }
20. private void button1_Click(object sender, EventArgs e)
21. {
22. l1 = textBox1.Text;
23. l2 = textBox2.Text;
24. l3 = textBox3.Text;
25. Form2 frm2 = new Form2();
26. frm2.ShowDialog();
27. }
28. }
29. }
Form2.cs
1. using System;
2. using System.Collections.Generic;
3. using System.ComponentModel;
4. using System.Data;
5. using System.Drawing;
6. using System.Linq;
7. using System.Text;
8. using System.Windows.Forms;
9.
10. namespace WindowsFormsApplication1
11. {
12. public partial class Form2 : Form
13. {
14.
15. public Form2()
16. {
17. InitializeComponent();
18.
19.
20. label4.Text = Form1.l1;
21. label5.Text = Form1.l2;
22. label6.Text = Form1.l3;
23.
24.
25. }
26.
27. }
28. }
Output chamber

Display data on Form2:

You might also like