小编use*_*442的帖子

单击时更改按钮颜色(多次单击/颜色)

我试图制作一个8x8按钮的数组,到目前为止它的工作原理.现在我偶然发现了一个问题.我希望按钮的颜色(背景色)在单击时更改.再次单击时更改为不同的颜色.

到目前为止这是我的代码:

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        Button[,] btn = new Button[8,8];

        public Form1()
        {
            InitializeComponent();

            for (int x = 0; x < btn.GetLength(0); x++)
            {
                for (int y = 0; y < btn.GetLength(1); y++)
                {
                    btn[x,y] = new Button();
                    btn[x,y].SetBounds(40 * x, 40 * y, 40, 40);
                    btn[x,y].Click += new EventHandler(this.btnEvent_click);
                    Controls.Add(btn[x, y]);
                    btn[x,y].BackColor = Color.Black;
                }
            }

            /* 
            btn.Click += new EventHandler(this.btnEvent_click);
            btn[x,y].Text = Convert.ToString(x+","+y);
            Controls.Add(btn);
            btn[x,y].Click += new EventHandler(this.btnEvent_click);
            */
        }

        private …
Run Code Online (Sandbox Code Playgroud)

c# colors button

4
推荐指数
1
解决办法
5万
查看次数

标签 统计

button ×1

c# ×1

colors ×1