label backgrond flicking on a WinForms user control has background image enabled

后端 未结 1 575
我寻月下人不归
我寻月下人不归 2020-12-20 06:56

I am working on a windows form project and having some problem with UserControl Double Buffering. I created a usercontrol and has a background image, then on top of it I hav

相关标签:
1条回答
  • 2020-12-20 07:20

    This is not a source of flicker that double-buffering can solve. When the UC repaints itself, it draws the background image, leaving holes where the controls go. The controls then each get to paint themselves, filling in the hole by first asking the UC to draw itself again to produce the background pixels, then draw themselves on top. The temporary hole is what you see as flicker.

    You can make it less objectionable by allowing the UC to draw itself in the client area of the controls so the background is already set correctly. Paste this code in the UserControl class:

    protected override CreateParams CreateParams {
      get {
        var parms = base.CreateParams;
        parms.Style &= ~0x02000000;  // Turn off WS_CLIPCHILDREN
        return parms;
      }
    }
    

    This doesn't make the painting any faster and may have side-effects. If that is still a problem then you need to make the BackgroundImage draw faster. Prescale it to the client size of the user control so it can be drawn without rescaling. Use the PixelFormat.Format32bppPArgb format for the bitmap, it is about 10x faster than any other one on most video adapters.

    0 讨论(0)
提交回复
热议问题