为了方便各路豪杰看代码,我复制相关代码如下: private const int Unit_length = 20;//单位格大小
private const int StartPrint = 32;//点坐标偏移量
private List<float> DataList = new List<float>();//数据结构----线性链表
private Pen TablePen = new Pen(Color.FromArgb(0x00, 0x00, 0x00));//轴线颜色
private Pen LinesPen = new Pen(Color.FromArgb(0xa0, 0x00, 0x00));//波形颜色
private void groupBox3_Paint(object sender, PaintEventArgs e)//在容器里面画波形
{
String Str = "";
Graphics g = e.Graphics;
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
e.Graphics.FillRectangle(Brushes.White, e.Graphics.ClipBounds);
for (int i = 0; i <= 30; i++)
{
e.Graphics.DrawLine(TablePen, StartPrint + i * Unit_length + 5, StartPrint - 14, StartPrint + i * Unit_length + 5, 17 * Unit_length);//画纵线
gp.AddString((i * 10).ToString(), this.Font.FontFamily, (int)FontStyle.Regular, 11, new RectangleF(StartPrint + i * Unit_length, 16 * Unit_length + 18, 400, 50), null);//添加文字
}
for (int i = 0; i <= 16; i++)
{
e.Graphics.DrawLine(TablePen, StartPrint +5, i * Unit_length + 18, StartPrint + 30 * Unit_length + 5, i * Unit_length + 18);//画横线
Str = Convert.ToString((16 - i) * 10);
if (i == 0)
Str = "65536";
if (i == 17)
break;
gp.AddString(Str, this.Font.FontFamily, (int)FontStyle.Regular, 12, new RectangleF(0, i * Unit_length + 16, 400, 50), null);//添加文字
}
e.Graphics.DrawPath(Pens.Black, gp);//文字画在表上
for (int i = 0; i < DataList.Count - 1; i++)//绘画波形部分
{
e.Graphics.DrawLine(LinesPen, StartPrint + 5 + i * 5 ,17 * Unit_length - DataList[i] * 4, StartPrint + 5 + (i + 1) * 5, 7 * Unit_length + 18 - DataList[i + 1] * 4);
}
}
private void AddData(float Data)//链表 给波形传数值
{
for (int i = 0; i < sz3.Length; i++)
{
DataList.Add(sz3[i]);
}
Invalidate();
}
for (int k = 0; k < (Q - 2); k = k + 2)//数组3里面是要绘画的数据 例如:4218,4200 ,4199之类的
{
sz3[m] = sz4[k] * b + sz4[k + 1];
m++;
}
|