Archie, I wanted to create a custom control for a gauge. I created a new user control and set the background image of it to the gauge i want then I draw the line of the gauge using the following code. Everything works great except the control 'flickers' when it is updated too fast. I set the Double Buffer to true and enabled AntiAliasing, however this does not seem to help. What can I do to prevent this flickering? Thank you
P.S. How do you post code in this forum?
protected override void OnPaint(PaintEventArgs e)
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
//call the base paint method
base.OnPaint(e);
// enable anti Aliasing
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// draw the objects
Pen pointer = new Pen(this.BackColor, needleWidth);// create an initial pointer for the gauge using the controls back color
// draw the pointer on the gauge
e.Graphics.TranslateTransform(Width * 0.5f, Height * 0.5f); // sets the center of the control as the point to rotate the needle around
e.Graphics.RotateTransform(180+n_value); //the value to rotate the needle based on a public "Value" property. Had to offset by 180 degrees
e.Graphics.DrawLine(pointer, 0, 0, 0, Height * 0.5f); // this sets the length of the needle to just under half the height
pointer.Dispose(); // release the resources