画面之间采用委托传递参数

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 
 

namespace WindowsFormsApplication2

{

public
delegate
void
delegateShow(int counter);

public
partial
class
Form1 : Form

{

public Form1()

{

InitializeComponent();

 
 

Form2 f2 = new
Form2();

f2.ShowCounter = new
delegateShow(showcounter);

f2.Show();

}

 
 

public
void showcounter(int counter)

{

this.Text = counter.ToString();

}

}

}

 
 

 
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 
 

namespace WindowsFormsApplication2

{

public
partial
class
Form2 : Form

{

public Form2()

{

InitializeComponent();

}

 
 

public
delegateShow ShowCounter;

int counter=0;

 
 

private
void button1_Click(object sender, EventArgs e)

{

counter++;

ShowCounter?.Invoke(counter);

}

}

}

 
 

  

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注