Home > Net >  Great god genuflect is begged a about two window to realize the value each other (similar to the two
Great god genuflect is begged a about two window to realize the value each other (similar to the two

Time:09-27

Great god genuflect is begged a problem, I want to implement a project by value each other between the two Form window, similar to the two chat window to send information, now I use a delegate from child Form to parent Form hair message: no problem, but is triggered by pressing the parent Form button instance, anti-fuzzy Form and to the child Form constructor parameter; So the question now is whether the parent form to the child form hair message, generated a child form every time, and I think can only generate a child form how to implement?


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,
  •  Tags:  
  • C#
  • Related