locked
在panel中能否使用CreateGraphics(),如果不能有代替的方法吗,谢谢 RRS feed

  • 问题

  • 编译的时候没有问题,调试的时候就出错
    未处理的“System.NotSupportedException”类型的异常出现在 System.Drawing.dll 中

            private bool[,] struArr = new bool[5, 5];
            private Color blockColor = Color.Red;

            private void lblMode_Paint(object sender, PaintEventArgs e)
            {
                Graphics gp = e.Graphics;
                gp.Clear(Color.Black);
                Pen p = new Pen(Color.White);
                for (int i = 31; i < 155; i = i + 31)
                    gp.DrawLine(p, 1, i, 155, i);
                for (int i = 31; i < 155; i = i + 31)
                    gp.DrawLine(p, i, 1, i, 155);
                        }

            private void lblMode_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left)
                    return;
                int xPos, yPos;
                xPos = e.X / 31;
                yPos = e.Y / 31;
                struArr[xPos, yPos] = !struArr[xPos, yPos];
                bool b = struArr[xPos, yPos];
                //问题
                Graphics gp = lblMode.CreateGraphics();
                //问题
                SolidBrush s = new SolidBrush(b ? blockColor : Color.Black);
                gp.FillRectangle(s, 31 * xPos + 1, 31 * yPos + 1, 30, 30);
                gp.Dispose();
            }

     

    2010年4月7日 2:14

答案

全部回复