xuejianhui

导航

C#双缓存.cs

protected override void OnPaint(PaintEventArgs e )
{
    //屏幕外的图像
    Graphics gxOff;

    //要双缓冲的位图
    if (m_bmpOffscreen == null)
    {
        m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
    }

    gxOff = Graphics.FromImage(m_bmpOffscreen);

    gxOff.Clear(this.BackColor);
    //绘制一些位图
    gxOff.DrawImage(bmpParent, 0, 0, bmpRect, GraphicsUnit.Pixel);

    //边界矩形
    Rectangle rc = this.ClientRectangle;
    rc.Width--;
    rc.Height--;

    //绘制边界
    gxOff.DrawRectangle(new Pen(Color.Black), rc);
    //从内存位图绘制
    e.Graphics.DrawImage(m_bmpOffscreen, 0, 0);

    base.OnPaint( e );
}

posted on 2012-11-21 10:13  xuejianhui  阅读(333)  评论(0编辑  收藏  举报