C# 控件闪烁问题

1、带背景图的Panel,改变尺寸时,panel和子控件删除问题

/// 
/// 加强版 Panel
/// 
class PanelEnhanced : Panel
{
    /// 
    /// OnPaintBackground 事件
    /// 
    /// 
    protected override void OnPaintBackground(PaintEventArgs e)
    {
        // 重载基类的背景擦除函数,
        // 解决窗口刷新,放大,图像闪烁
        return;
    }

    /// 
    /// OnPaint 事件
    /// 
    /// 
    protected override void OnPaint(PaintEventArgs e)
    {
        // 使用双缓冲
        this.DoubleBuffered = true;
        // 背景重绘移动到此
        if (this.BackgroundImage != null)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            e.Graphics.DrawImage(
                this.BackgroundImage,
                new System.Drawing.Rectangle(0, 0, this.Width, this.Height),
                0,
                0,
                this.BackgroundImage.Width,
                this.BackgroundImage.Height,
                System.Drawing.GraphicsUnit.Pixel);
        }
        base.OnPaint(e);
    }
}

继承PanelEnhanced 

2、FlowLayoutPanel调整子控件尺寸导致的闪烁

this.flowlayoutPanel1.SuspendLayout();
// 调整子控件尺寸
// ...
this.flowlayoutPanel1.ResumeLayout(true);

 

附:

解决Winform应用程序中窗体背景闪烁的问题

如何避免多控件窗体重新布局时闪烁

C#解决动态添加控件时,控件闪烁的问题

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