I created one Windows Forms User Control, I drag, dropped a panel inside it and over the panel I drew the graph in the Paint event of Panel.
private void pnlViewer_Paint(object sender, PaintEventArgs e)
{
e.Graphics.TranslateTransform(pnlViewer.AutoScrollPosition.X, pnlViewer.AutoScrollPosition.Y);
e.Graphics.FillRectangle(Brushes.Black, Screen.PrimaryScreen.Bounds);
//**draw Y Axis**
int y;
for (int i = 0; i <= 50; i++)
{
y = (i * cellHeight) + cellHeight;
e.Graphics.DrawLine(new Pen(Color.FromArgb(50, 50, 50)),
new Point(0, y), new Point(pageWidth, y));
}
//**draw X Axis**
int x;
for (int i = 0; i < 50; i++)
{
x = (i * cellWidth) + ribbonWidth;
e.Graphics.DrawLine(new Pen(Color.FromArgb(50, 50, 50)),
new Point(x, 0), new Point(x, pageHeight));
}
DrawWaveForm(e.Graphics); **// Here the actual data of graph will draw**
}
When I drag this user control onto a WinForm, it calls this paint event of User Control from windows form, but while calling to this event the graph is shown but after some time the graph becomes blank.
I tried Invalidate(true), Update(), Refresh()
all such methods but they were of no use.
Actually it shows half of the graph over form and after next the same paint event is fired then it shows the full graph that I require, but actually I want on first Paint event instead of half graphs showing the full graph.