跨窗体事件:例如从一个窗体改变另一个窗体button的颜色,首先需要将需要改变button的属性改为public
using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { private Form2 _frm; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var form2 = new Form2(); _frm = form2; form2.Show(); } public bool IsClick; private void button2_Click(object sender, EventArgs e) { IsClick = !IsClick; if (IsClick) _frm.button1.BackColor = Color.Red; else if (IsClick == false) { _frm.button1.BackColor = SystemColors.Control; } } } }