大家好,我正在动态创建一些按钮,当用户单击按钮时,我需要将所选按钮的 BackColor 设置为一些突出显示的颜色,根据我编写的代码,它正在为每个按钮应用颜色,而不是那个我需要为用户单击的按钮应用颜色
我创建按钮的代码如下
for(int i=0;i<5;i++)
{
Button btyDynamic = new Button();
btyDynamic .Click += new EventHandler(btyDynamic _Click);
btyDynamic .AutoSizeMode = AutoSizeMode.GrowAndShrink;
btyDynamic .AutoSize = true;
btyDynamic .Text = i.ToString();
btyDynamic .Tag = i.ToString();;
}
protected void btyDynamic(object sender, EventArgs e)
{
Button btn= sender as Button;
string strTag= btn.Tag.ToString();
switch(strTag)
{
case "0":
btn.BackColor=Color.LightSteelBlue;
break;
// Like this I am writing, now when in Case2 I need to remove the color of the first button and to show the backcolor of second button
}
}