猿问

FlowLayout 控制事件

FlowLayout 中有很多按钮。当我单击按钮时,我希望正常颜色发生变化。当我第一次单击时,按钮的颜色会发生变化。这里没有问题,但是当我第二次点击另一个按钮时,我之前点击的按钮没有恢复。我能怎么做 ?


 int j =1;

    foreach (...)

                 {

                     BunifuFlatButton newButton = new BunifuFlatButton();

                     {

                         newButton.Name = string.Format("Button{0}", j);

                         flowLayoutPanel1.Controls.Add(newButton);

                         newButton.Click += NewButtonOnClick;

                         j++;

                     }


                 }





  private void NewButtonOnClick(object sender, EventArgs eventArgs)

        {

            BunifuFlatButton btn = (BunifuFlatButton)sender;

            btn.Normalcolor = Color.FromArgb(37, 66, 80);

        }


不负相思意
浏览 210回答 1
1回答

湖上湖

&nbsp; List<BunifuFlatButton> btnss = new List<BunifuFlatButton>();&nbsp; &nbsp; private bool pressed = false;&nbsp; &nbsp; private void NewButtonOnClick(object sender, EventArgs eventArgs)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; BunifuFlatButton btn = (BunifuFlatButton)sender;&nbsp; &nbsp; &nbsp; &nbsp; if (pressed)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btnss[0].Normalcolor = Color.FromArgb(37, 37, 37);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btn.Normalcolor = Color.FromArgb(37, 66, 80);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pressed = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btnss.Clear();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btnss.Add(btn);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (btnss.Count != 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btnss[0].Normalcolor = Color.FromArgb(80, 80, 80);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btn.Normalcolor = Color.FromArgb(37, 66, 80);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btnss.Clear();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btnss.Add(btn);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pressed = true;&nbsp; &nbsp; &nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答