Transfer data and methods between forms:
Code
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 Transfer Data between Windows 1
11 {
12 Public Partial Class Form1: Form
13 {
14 Public Form1 ()
15 {
16Initializecomponent ();
17}
18
19 Private Void Button2_click ( Object Sender, eventargs E)
20 {
21 Form2 FM2 = New Form2 ();
22 Fm2.form1 = This ;
23 Fm2.show ();
24 }
25 Public Void Getnameaddpwd ( String Name, String PWD)
26 {
27Textbox1.text=Name. Trim ();
28Textbox2.text=PWD. Trim ();
29}
30 }
31 }
32
(2) This is a registration page:
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;
Pass data between namespace windows 1
{
Public partial class form2: Form
{
Public form1 form1; // A form1 variable is declared here to call the method in the form1 class. And initialize it for the function in the login interface.
Public form2 ()
{
Initializecomponent ();
}
Private void form2_load (Object sender, eventargs E)
{
}
Private void button#click (Object sender, eventargs E)
{
Form1.getnameaddpwd (textbox1.text, textbox2. Text); // call the method in form1 to pass the value to the login interface
Form1.show ();
This. Hide ();
}
}
}
In fact, it can be used not only for data transmission, but also for calling methods. For example, you can re-open a data adding interface in the gridview. After adding data, you can call the method on its main interface to refresh the data. In this way, you can immediately see the added data on the main interface after adding the data.