兩個(gè)窗體form1和form2
點(diǎn)擊form1按鈕跳轉(zhuǎn)到form2
點(diǎn)擊form2按鈕,form1中按鈕文字變化
form1中代碼
namespace TestUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.settxt += SetBtnText;
form2.Show();
}
public void SetBtnText(string txt)
{
button1.Text = txt;
}
}
}
form2中代碼
namespace TestUI
{
public partial class Form2 : Form
{
public delegate void SetTextToBtn(string txt);
public event SetTextToBtn settxt;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string txt = "2018 新年快樂(lè)";
settxt(txt);
}
}
}