Form1 form:
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}
Private void btn1_Click (object sender, EventArgs e)
{
Form2 f2=new Form2 (txt1. Text, DoSth);
F2. The Show ();
}
//the string variable values assigned to the text box
Public void DoSth (string MSG)
{
Txt1. Text=MSG;
}
}
Form2 form:
Public delegate void MyDel (string STR);
Public partial class Form2: Form
{
Public Form2 ()
{
InitializeComponent ();//initialize the form
}
Private MyDel _mdl;
Public Form2 (string STR, MyDel MDL) : this ()
{
TextBox1. Text=STR;
Enclosing _mdl=MDL;
}
Private void button1_Click (object sender, EventArgs e)
{
//the delegate must judge first
If (this. _mdl!=null)
{
Enclosing _mdl (textBox1. Text);
Enclosing the Close ();
}
}
}
CodePudding user response:
Made singleton child window, a window is the new one, but is created on one side, don't hide, rather than close,