C#透明panel移动或缩放时闪烁

之前做了一个可以运行时自由调节的透明panel作为一个候选框,但是移动或缩放时会闪烁,很影响体验,原因就是控件背景的刷新的问题。要解决这个办法只需要开启双缓冲即可,由于初学c#,理解的不是很深,所以不多做解释。

主要参考了https://blog.csdn.net/leejunki822/article/details/50617831

给form里直接新建了类:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace Test
{
    //开启双缓冲
    class MyPanel:Panel
    {
        public MyPanel()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
        }
    }
}

然后,纵享丝滑

猜你喜欢

转载自blog.csdn.net/wi162yyxq/article/details/96520911