C# GDI+ 擦除

方法一、利用背景覆盖 

        SolidBrush sb = null;
        Rectangle r;
        private void GraphicsDeviceInterfacePlusForm_Load(object sender, EventArgs e)
        {
            g = this.CreateGraphics();
            r = new Rectangle(0, 0, 10, 10);
            g.FillRectangle(Brushes.Blue, r);
            sb = new SolidBrush(this.BackColor);
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            g.FillRectangle(sb, r);
            r.Offset(0, 10);
            g.FillRectangle(Brushes.Blue, r);
        }

方法二、利用重绘
        private void timer1_Tick(object sender, EventArgs e)
        {

            this.Invalidate();
        }

        Rectangle rs = new Rectangle(0, 0, 10, 10);
        protected override void OnPaint(PaintEventArgs e)
        {
            g = e.Graphics;
            g.FillRectangle(Brushes.Blue, rs);
            rs.Offset(0, 10);
        }

还有其他方法 利用临时生成image清除重绘,利用控件改变坐标等等。

你可能感兴趣的:(C#应用)