1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (objBitmap != null)
{
Graphics g = this.CreateGraphics();
g.DrawImage(objBitmap, 0, 0, this.Width, this.Height);
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
DrawGraphImage();
}
private void DrawGraphImage()
{
int i;
objBitmap = new Bitmap(this.Width, this.Height);
g = Graphics.FromImage(objBitmap);
//White background
g.FillRectangle(new SolidBrush(Color.White), 0, 0, this.Width, this.Height);
if (wafeForms.Count != 0)
{
//Axes
g.DrawLine(axePen, this.marginLeft, this.Height - yMargin, this.Width - this.marginRight, this.Height - yMargin);
g.DrawLine(axePen, this.marginLeft, this.yMargin, this.marginLeft, this.Height - yMargin);
double[,] markYArray = GetYMarkers();
double[,] markXArray = GetXMarkers();
for (i = 0; i < markYArray.GetUpperBound(0) + 1; i++)
{
g.DrawLine(axePen, this.marginLeft - 5, this.Height - this.yMargin - (int)Math.Round(markYArray[i, 0]), this.marginLeft, this.Height - this.yMargin - (int)Math.Round(markYArray[i, 0]));
g.DrawString(markYArray[i, 1].ToString(), Font, new SolidBrush(Color.Black), this.marginLeft - 30, this.Height - this.yMargin - (int)Math.Round(markYArray[i, 0]) - 5);
}
for (i = 0; i < markXArray.GetUpperBound(0) + 1; i++)
{
g.DrawLine(axePen, this.marginLeft + (int)Math.Round(markXArray[i, 0]), this.Height - this.yMargin, this.marginLeft + (int)Math.Round(markXArray[i, 0]), this.Height - this.yMargin + 5);
g.DrawString(markXArray[i, 1].ToString(), Font, new SolidBrush(Color.Black), this.marginLeft + (int)Math.Round(markXArray[i, 0]), this.Height - this.yMargin + 10);
}
//Draw waveforms
foreach (WaveForm wf in wafeForms)
{
double xS = GetXScale(wf.length);
double yS = GetYScale();
int modx = 1;
for (i = 0; i < wf.length - modx; i += modx)
{
g.DrawLine(wf.pen, (int)Math.Round((wf.xScale[i] - minX) * xS) + this.marginLeft, this.Height - (int)Math.Round((wf.data[i] - minY) * yS) - this.yMargin, (int)Math.Round((wf.xScale[i + modx] - minX) * xS) + this.marginLeft, this.Height - (int)Math.Round((wf.data[i + modx] - minY) * yS) - this.yMargin);
}
}
}
this.Refresh();
} |