1 回答
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
要按順序識別兩個(gè)按鈕,您需要將第一個(gè)按鈕的引用存儲為類級變量,例如previousButton。在點(diǎn)擊代碼的末尾指定它,以便您可以在下次點(diǎn)擊時(shí)參考它。
public partial class Form1 : Form
{
private Button previousButton = null;
public Form1()
{
InitializeComponent();
button1.Click += Buttons_Click;
button2.Click += Buttons_Click;
}
private void Buttons_Click(object sender, EventArgs e)
{
if (previousButton != null)
{
// do something with previousButton
}
// code to work with the currently clicked button
// as (Button)sender
// remember the current button
previousButton = (Button)sender;
}
}
如果按鈕序列總是成對發(fā)生,那么一旦成對序列完成,設(shè)置previousButton回null. 這告訴您將開始一個(gè)新的“序列”。
- 1 回答
- 0 關(guān)注
- 117 瀏覽
添加回答
舉報(bào)
