![](/img/trans.png)
[英]While Loop Function after a button is pressed and stop looping when another button is pressed C#
[英]reset the color of a previously pressed button after another button is pressed c#
我正在使用C#Windows窗體應用程序,並且遇到重置按鈕背面顏色的問題。
通過單擊按鈕,我需要它來更改其背景色並重置先前按下的按鈕的背景色。
請注意,我在表單中有很多按鈕,並且我使用“發件人”將相同的單擊事件應用於所有按鈕。
您需要跟蹤單擊的最后一個按鈕。 添加一個私有字段,然后在on click事件處理程序中對其進行操作:
class Form1 : Form
{
private Button _lastButtonClicked;
protected void ClickHandler(object sender, EventArgs e)
{
if (_lastButtonClicked != null)
_lastButtonClicked.BackColor = Color.whatever;
_lastButtonClicked = sender as Button;
_lastButtonClicked = Color.newcolor;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.