-3
動態添加按鈕座標X = 100,Y = 200;並通過點擊,表單必須將背景顏色更改爲紅色,通過第二次點擊綠色。如何將動態按鈕及其事件添加到Windows窗體?
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?
}
}
歡迎#1。這對這個網站來說確實是一個糟糕的問題。請閱讀[常見問題]和[問]結果.. –
@Geo Man看起來你已經有你的解決方案,爲什麼你問/ – 2013-09-28 12:00:36
private void Mouse_Click(Object s,EventArgs e) { //做什麼這裏讓按鈕更改窗體顏色? } :\ – AYETY