3

I have a simple panel that is used as a drawing surface. The goal here is to draw a 4 pixel wide outline around a child ListView under certain circumstances. I would like to make the outline pulsate when something can be dragged into it.

I am just drawing a simple rectangle around the ListView and updating the opacity of the rectangle inside of a timer tick event. When the opacity is changed, the border is re-drawn. I am double-buffering the painting at this point. I am also only allowing a redraw every 15 ticks or so (the timer interval is 20 ms). After all of this, the drawing process still flickers a bit. This is not acceptable, so I need some guidance on how I could avoid this.

I don't see a way around painting the control quite often. There needs to be a smooth transition from opaque to solid and back again. When I lower the tick interval enough (down to about 300 -500 ms), the flashing stops, but the refresh rate is too slow.

I am open to any and all ideas. Perhaps the way I am approaching this is just plain wrong, or perhaps one of you have already created a glow effect and know what to do. Thanks for any help in advance.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Ed S.
  • 122,712
  • 22
  • 185
  • 265

6 Answers6

4

I stumbled on a solution for this if anyone is interested. It turns out that the flashing is caused by the painting of the background. I used SetStyle to tell the control that I will be handling all of the painting.

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

I then first paint a transparent color over the region, and then I paint my border. I bit of a hack, but it works like a charm.

EDIT: And remember to double buffer the image as well.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
3

Set DoubleBuffered = true on the form.

mannu
  • 793
  • 3
  • 10
1

I don't have a strong answer, but since you have none, I'll post anyway:

First, I have never used the System.Drawing.ImageAnimator class, but could that be a better approach for you?

Second, if that fails, have you tried not using double-buffering? It's a long shot, but maybe your double-buffering code is actually making it worse.

rice
  • 1,063
  • 6
  • 17
  • +1 because you alerted me to the ImageAnimator class which is useful for another project of mine. – Ed S. Oct 09 '08 at 00:25
1

I'm sorry in advance that this likely won't help but: WPF has animations and could at least in theory do this smoothly.

Mark Allen
  • 1,230
  • 1
  • 15
  • 17
0

Long shot, but have you tried

SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

On the Panel Control?

JamesSugrue
  • 14,891
  • 10
  • 61
  • 93
0

You also may want to look at doing the drawing on a bitmap and then just displaying the bitmap if it has changed. Just my 2c.

Craig
  • 11,614
  • 13
  • 44
  • 62