Home > Net >  Form between the values
Form between the values

Time:10-05

A parent form, there is a number, a child form, there is a button, when I click on the button, the inside of the parent form number plus one, with entrust should be how to write, pray, answer

CodePudding user response:

LINQ is: are you sure?

CodePudding user response:

This example is a child form click the button, the parent form an additional data, and you want to be the basic agreement
https://blog.csdn.net/hanjun0612/article/details/50071539

CodePudding user response:

Child form:
 public delegate void TransfDelegate (int num); 
Public partial class Form2: Form
{
The public event TransfDelegate TransfEvent;
Public Form2 ()
{
InitializeComponent ();
}

Private void button1_Click (object sender, EventArgs e)
{
TransfEvent (1);
}
}

Main form:
 public partial class Form1: Form 
{
Public _click ()
{
InitializeComponent ();
}

Private void button1_Click (object sender, EventArgs e)
{
Form2 form=new Form2 ();
Form. TransfEvent +=Form_TransfEvent;
Form the ShowDialog ();
}

Private void Form_TransfEvent (int num)
{
Label1. Text=(string) IsNullOrEmpty (label1. Text)? 0: int. Parse (label1. Text) + num.) the ToString ();
}
}

CodePudding user response:

You can create a new class, with static variables,
The class Class1
{
Public static int _a;
}
The main form loads Class1. _a=int. Parse (label2. Text);
When the child form click Class1. _a + +;
Main form to add a clock label2. Text=Class1. _a. The ToString ();

CodePudding user response:

Parent form name. The variable name + +;

CodePudding user response:

Child form

 
The Action Do;

Private void Btn_Click (object sender, EventArgs e)
{
Do ();
}



Parent form

 
Private void Btn_Click (object sender, EventArgs e)
{
Form1 Form1=new _click ();
Form1. Do=Method;
}
int index=0;
Void Method ()
{
Index++;
Label. The Text=index. The ToString ();
}


CodePudding user response:

Implementation method are many, static, public variables or methods, entrust, etc.;
Not static, the public that the # 2 has given the delegate, to give you specific code analysis:
child form:
 
Public delegate void AddValueHandle (your params);//define a delegate;
The public event AddValueHandle AddValueEvent;//define a triggering event;
.
//use the following code in need of trigger, such as your child form button click event:
If (AddValueHandle!=null) AddValueEvent. Invoke (your params);


The main form:
Such as child form instance: sonWnd;
 
SonWnd. AddValueEvent +=delegate {doing something};

Or:
 
SonWnd. AddValueEvent +=SonWnd_AddValueEvent;

.

Private void SettingCtrl_SaveClicked (your params)
{
//dosomething
}

CodePudding user response:

refer to 7th floor near 1210 response:
implementation method are many, static, public variables or methods, entrust, etc.;
Not static, the public that the # 2 has given the delegate, to give you specific code analysis:
child form:
 
Public delegate void AddValueHandle (your params);//define a delegate;
The public event AddValueHandle AddValueEvent;//define a triggering event;
.
//use the following code in need of trigger, such as your child form button click event:
If (AddValueHandle!=null) AddValueEvent. Invoke (your params);


The main form:
Such as child form instance: sonWnd;
 
SonWnd. AddValueEvent +=delegate {doing something};

Or:
 
SonWnd. AddValueEvent +=SonWnd_AddValueEvent;

.

Private void SettingCtrl_SaveClicked (your params)
{
//dosomething
}


 
SonWnd. AddValueEvent +=SonWnd_AddValueEvent;

.

Private void SonWnd_AddValueEvent (your params)
{
//dosomething
}
  •  Tags:  
  • C #
  • Related