I have a component, an inherited Panel, where I am overriding the OnPaint event to draw a graph with 500 points. Since I need to do some selection on the graph, it is flickering. I have found this DoubleBuffered property but when I set it to True, in the panel constructor, the drawing disappears. I debug it and I see that the drawing methods still execute but there is nothing on the panel. Does anyone know why would this happen?
This is .NET 3.5 - C#. Winforms application
try
{
Graphics g = e.Graphics;
//Draw _graphArea:
g.DrawRectangle(Pens.Black, _graphArea);
_drawingObjectList.DrawGraph(g, _mainLinePen, _diffLinePen, _dotPen, _dotBrush, _notSelectedBrush, _selectedBrush);
DrawSelectionRectangle(g);
g.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Panel descendant constructor:
this.BackColor = Color.White;
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.UpdateStyles();