C#WinForm绘图 - 如何清除和重绘

Sto*_*art 2 c# drawing winforms

这是我的游戏的屏幕截图.在左边是我的问题,似乎仍然存在"旧画".在右边是它应该是什么.

http://img682.imageshack.us/img682/1058/38995989.jpg

绘图代码

        Graphics g = e.Graphics;

        for (int i = 1; i < 27; i += 1)
        {
            for (int j = 0; j < 18; j += 1)
            {
                ZPoint zp = zpoints[i, j];

                if (zp != null)
                {
                    g.DrawImage(zp.sprite_index, new Point(zp.x, zp.y));

                    Image arrow;
                    if (zp.sprite_index == spr_green_zpoint)
                    {
                        arrow = spr_green_arrows[zp.image_index];
                    }
                    else if (zp.sprite_index == spr_red_zpoint)
                    {
                        arrow = spr_red_arrows[zp.image_index];
                    }
                    else
                    {
                        arrow = spr_grey_arrows[zp.image_index];
                    }

                    g.DrawImage(arrow, new Point(zp.x - 4, zp.y - 4));
                }
            }
        }

        if (latest_p1 != -1 && latest_p2 != -1)
        {
            ZPoint zp = zpoints[latest_p1, latest_p2];

            if (zp != null)
            {
                g.DrawImage(spr_focus, new Point(zp.x - 6, zp.y - 6));
            }
        }
Run Code Online (Sandbox Code Playgroud)

Ada*_*son 7

Control该类有几种方法可以处理重绘:

  • Invalidate - 此方法将控件的特定区域标记为无效,并将在下一个绘图操作中重绘它
  • Update - 此方法触发重绘任何无效区域
  • Refresh - 此方法使控件的整个表面无效并立即重绘它.相当于召唤Invalidate()Update()立即连续.