Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I've created an amazing control for my application in the form of a rotating slider, which is being ruined by flickering.

It consists of 3 elements:
• valueCircle, an OvalShape, in which a pie is drawn to represent the value, causing the flickering
• the turning knob
• the notch

[View Image]

I tried creating a class inheriting from OvalShape, overrode onPaint, changed all of the relevant properties in pe.Graphics to HighQuality and then called MyBase.onPaint(pe), using the new high quality settings (in other words, followed every tutorial out there for removing flickering) to no avail.

I understand that redrawing the pie in the mouse move event is taxing, but it's the only way I can think of to achieve the desired effect.

Any help would be appreciated.

Thanks,

Rix

What I have tried:

All tutorials out there on doublebuffering
Posted
Updated 8-Feb-17 10:14am
v2
Comments
Member 11450536 9-Feb-17 9:16am    
Any reason for the one-star vote?

1 solution

I suggest the following to solve this problem :
- your knob-control should derive from Control - it should not be a UserControl.
- Don't use further controls - paint them by yourself.
- inside this your override the OnPaint-Method and do all necessary drawing by yourself. So you only have to Invalidate one Control instead of 3
- possible optimation could be : you draw your knob and the scale (if you have one) into an image (one time at the beginning - after HandleCreated or after Resizing the Control). If you now change the value of the knob (the location of the dot on it) you first draw the saved image and then the dot at it's new location.

Each of this steps will make the repainting of your control much faster (and reduces the flickering).
 
Share this answer
 
Comments
Member 11450536 9-Feb-17 9:22am    
I forgot to mention how I was approaching it;

When the user drags the mouse up, the knob appears to turn (the dot is repositioned around in a circle) and the pie has a greater sweep angle.

The turning knob and notch are oval-and rectangleshapes. I don't invalidate anything, I create a new bitmap, draw the pie using Graphics.FromImage(bmp) and set valueCircle's backgroundImage to bmp.
Ralf Meier 9-Feb-17 11:26am    
OK ... then I have understood your approach right.
To explain what I have written :
Each time something of a control is repainted the control invalidates itself. The Invalidate causes the OnPaint-Method of the Control.
Your Flickering comes because you first (I suppose) draw your Pie.
Now you redraw your Circle (over the Pie) and at last you draw the Rectangle at the new Position.
Am I right so far ?

What I would change is :
At first I create a graphic (image) which represents the constant part of your control - this means an empty ValueCircle and a Knob without the Notch on it.
As long as you didn't resize your Control you need not recalculate this image.
If you change your Knob-Value (with the Property or with a Mouse-Action) you invalidate your Control (what calls the OnPaint-Method of this Control).
Now you draw your Image.
Then draw the Pie, but not complete - only as the required segment and at lost draw the Notch at the right position.

The only way to prevent the Flickering is to reduce the repainting as much as possible ...

Sorry ... I don't know a better way ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900