动态添加坐标 X=100, Y=200 的按钮;通过单击,表单必须将背景颜色更改为红色,第二次单击变为绿色。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int X = 100;
private int Y = 200;
Button btn = new Button();
private void Form1_Load(object sender, EventArgs e)
{
this.Controls.Add(btn);
btn.Location = new Point(X, Y);
btn.Text = "Click";
btn.Click += new EventHandler(Mouse_Click);
}
private void Mouse_Click(Object s, EventArgs e)
{
// what to do here to make button change Form color?
}
}