说明(2017-11-23 22:17:34):
1. 蒋坤的作业,点击窗体1里面的按钮,出现窗体2;点击窗体2里的按钮,窗体1改变背景色。
2. 做完窗体传值后,这个作业就很简单了。
代码:
Form1:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _06_窗体传值 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 f2 = new Form2(ChangeColor); f2.Show(); } private void ChangeColor() { this.BackColor = System.Drawing.Color.Black; } } }
Form2:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _06_窗体传值 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private Action _a; public Form2(Action a) : this() { this._a = a; } private void button1_Click(object sender, EventArgs e) { if (_a != null) { _a(); } } } }