|
-
Feb 5th, 2006, 09:59 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] User control Flickering
I have a user control that I created using GDI+, and .Net 2005. But there is a lot of flickering. I turned on DoubleBuffering and the flicker got ten times worse. The control that I created is a level meter( the meter on some audio devices that show the audio levels. Usually a bar that is green to yellow to red). So the needs to refresh about every 100 milliseconds.
The way I designed it makes it look a bit like led lights. When the value lights up the led lights. And they are darened when not higher than the current value. I've attached what the control looks like. Anyone have an idea how I can get rid of the flickering, or reduse it? Thanks
-
Feb 5th, 2006, 10:19 PM
#2
Re: User control Flickering
I'm no guru at this stuff but I'd think that you'd want to redraw as little as possible at each stage. If you are just refreshing the control and handling the drawing on the Paint event then I'd guess that that is less efficient than it needs to be. Obviously you must redraw the whole thing on the Paint event, but I'd suggest that each time you check the level you only actually redraw the parts that need it. You would test the current level and the previous level, then only redraw the boxes that need to change colour, e.g. if last recorded level was 10 and new level is 12 just redraw boxes 11 and 12 in bright colour, or if last level was 7 and current level is 3 just redraw boxes 4, 5, 6 and 7 in dark colour.
-
Feb 6th, 2006, 11:56 AM
#3
Fanatic Member
Re: User control Flickering
You are not required to Paint the whole control in the Paint event, which you shouldn't use when you are creating a user control as it will occur after the underlying base control is painted, use the OnPaint override instead so you are in full control (possibly even the OnBackGroundPaint as well). You only have to redraw the invalidated region which is given to you by the PaintEventArgs class (e) (in some cases that will be the whole control)
e.ClipRectangle gives you the rectangle that has been invalidated.
You should invalidate only the rectangle that needs redrawing, then in the overriden OnPaint you should calculate which elements fit in that rectangle and only redraw them.
The actual drawing takes up the most time, so it's OK to have bulk load of mathematics in order to prevent the unneeded repainting.
Last edited by grilkip; Feb 6th, 2006 at 12:03 PM.
"so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman
-
Feb 6th, 2006, 12:13 PM
#4
Addicted Member
Re: User control Flickering
Make sure you use the graphics object supplied by the paint event and do not use CreateGraphics
Supercharged
-
Feb 6th, 2006, 12:30 PM
#5
Fanatic Member
Re: User control Flickering
That's right, you shouldn't use CreateGraphics, but you also shouldn't use the Paint event as it will occur after the base control has already been painted. You must override the OnPaint sub for efficiency's sake.
"so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman
-
Feb 6th, 2006, 02:29 PM
#6
Re: User control Flickering
In addition to using the OnPaint override you can benefit tremendously by creating a backbuffer.
Here is what I use in my controls to creat th buffer.
VB Code:
#Region " Constructors "
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()
End Sub
#End Region
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 6th, 2006, 02:51 PM
#7
Re: User control Flickering
This is c#, but I was doing something similar, but with alot more calls to FillRect than it appears you have..
http://www.vbforums.com/showthread.php?t=370733
What I figured out, eventually, was that I nearly eliminated the flicker by doing all my individual rectangle draws to a bitmap object, and only calling DrawImage once with the completed bitmap..
Bill
-
Feb 6th, 2006, 04:12 PM
#8
Thread Starter
Frenzied Member
Re: User control Flickering
Thanks for all the input. Right now I have somethign that takes precedence over this now, so I'm nto going to be able to try these fixes for a couple days. But from what I've read I think this is resolved.
-
Jun 11th, 2014, 05:59 AM
#9
New Member
Re: User control Flickering
 Originally Posted by Supercharged
Make sure you use the graphics object supplied by the paint event and do not use CreateGraphics
Supercharged
You are a genius. This solved my problem completely!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|