首页 > 解决方案 > 如何创建可以在 Windows 窗体中单击的黑色矩形?

问题描述

System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
        System.Drawing.Graphics formGraphics;
        formGraphics = this.CreateGraphics();
        for (int ii = 0; ii != (10); ii++)
        {
            for (int i = 0; i != (10); i++)
            {
                formGraphics.FillRectangle(myBrush, new Rectangle(i * 30, ii*30, 20, 20));
            }
        }
        myBrush.Dispose();
        formGraphics.Dispose();

我正在尝试编写扫雷代码。我基本上是在尝试创建一组用户可以单击的矩形,但是当我尝试使用上面的代码时,我所拥有的只是一组用户无法与之交互的 10x10 矩形。

标签: c#winforms

解决方案


推荐阅读