Rendering controls on glass: Solution found, needs double-buffering/perfecting

后端 未结 2 690
梦谈多话
梦谈多话 2021-01-30 05:16

I (finally!) found a way of rendering Windows.Forms controls on glass that doesn\'t seem to have any major drawback nor any big implementation time. It\'s inspired by this artic

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 05:43

    I had a problem with flickering before (lots of controls on the form, user controls). Tried almost everything. This is what worked for me:

    Have you tried putting this in your form class?

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
                cp.ExStyle |= 0x00080000; // WS_EX_LAYERED
                return cp;
            }
        }
    

    And in your constructor you have to enable double buffering, otherwise it won't work:

    this.DoubleBuffered = true;
    this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    

    It only works when aero is enabled, if not it can make flickering even worse.

    and you can also add this

      protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
    
                    cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
                return cp;
            }
        } 
    

    to your UserControls class.

提交回复
热议问题