In the past two days, the WinForm program needs to be implemented, and an ASP inventory change function module needs to be converted into a Winform program. Therefore, this situation occurs when values are transferred between forms, I used to do this before when I went to work in ZhaoQing. At that time, I started the Winfom program, mainly for Machine Communication, which is closely related to the single-piece mode. After about four months, I really forgot about it. I started to do this, so I had no choice but to start learning again. At that time, the technical manager told me about the Commission. I understood the general idea during the incident. It was just a waste of time. I didn't understand it. Now I have spent some time doing a DEMO and applying it to the actual development environment. Although many problems have occurred during the application process, I cannot predict it, maybe the foundation is not reliable, the short circuit or ideology of the brain is vague, and some basic concepts are not remembered, which leads to the failure of passing values by the child to the parent, the parent form cannot display the desired data. The DEMO made by myself can be displayed on the contrary. It is very strange, but I also know that the problem is that the constructor in the parent form has never been closely linked with the instance. As a result, I always fail to pass the value myself.
Here I mainly have three WINFORM forms: MainParent, ChildForm, ThirdForm, MainParen ChildForm, ChildForm, and ThirdForm. Now I have an entity class, for more information, see:
First, I define the delegate and the delegate event in my third form,
In addition, I need to receive events triggered by the third form in the 2nd forms ChildForm, and then fill in the required values based on the events.
The Code is as follows:
Code
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Namespace WinFormSendValue
{
Public partial class ThirdForm: Form
{
Public delegate void SetValueSend (UserInfo userinfo); // defines the delegate
Public SetValueSend sendEvent; // declare a delegate-type event
Public ThirdForm (string aa)
{
InitializeComponent ();
}
Private void button#click (object sender, EventArgs e)
{
UserInfo model = new UserInfo (); // entity class
Model. UserName = this. textBox1.Text;
Model. PassWord = this. textBox2.Text;
If (sendEvent! = Null)
{
SendEvent (model );
}
This. Visible = false;
}
}
}
The code above is the delegate and event defined in Form 3, and the time when the event triggers the value transfer.
Then, you need to obtain the value passed in Form 3 in Form 2, and you must subscribe to the event, and then reference the conditional function after the event is triggered.
For more information, see the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinFormSendValue
{
public partial class ChildForm : Form
{
private ThirdForm thirdfrm = new ThirdForm("aa");
public ChildForm()
{
Initialize