How to avoid screen flickering when a control needs to constantly redraw to C #?

I have a simple panel that is used as a drawing surface. The goal is to, under certain circumstances, draw a 4-pixel outline around the child ListView. I would like to make the circuit pulsating when something can be pulled into it.

I just draw a simple rectangle around the ListView and update the transparency of the rectangle inside the timer event. When the transparency changes, the border is redrawn. At this moment I am duplicating the picture. I also allow redrawing every 15 ticks or so (the timer interval is 20 ms). After all this, the drawing process still flickers a bit. This is unacceptable, so I need to be guided by how I could avoid this.

I do not see the ability to draw control quite often. There should be a smooth transition from opaque to solid and vice versa. When I decrease the tick interval (to about 300-500 ms), the blinking stops, but the refresh rate is too low.

I am open to all ideas. Perhaps the way I'm approaching this is simply wrong, or perhaps one of you has already created a glow effect and knows what to do. Thanks for any help in advance.

+3
source share
6 answers

I came across a solution for this, if anyone is interested. It turns out that the blinking is caused by a background picture. I used SetStyle to tell the control that I would process the whole picture.

SetStyle(ControlStyles.SupportsTransparentBackColor |
         ControlStyles.Opaque |
         ControlStyles.UserPaint |
         ControlStyles.AllPaintingInWmPaint, true);

Then I first draw a transparent color over the region, and then draw my border. I hacked a bit, but it works like a charm.

: .

+4

DoubleBuffered = true .

+3

, , :

-, System.Drawing.ImageAnimator, ?

-, , ? , , , .

+1

, , , : WPF , , .

+1

,

SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

In the control panel?

0
source

You may also need to look at the drawing on the bitmap, and then just display the bitmap if it has changed. Just my 2c.

0
source

Source: https://habr.com/ru/post/1698060/


All Articles