下面给你写了一个代码,采用的方式是显示满5个点后,后面接收的数据会在最后一个显示,前面的四个会向前移一格,你也可以采用另一个方式就是显示满5个点后再从重从头开始显示的方式,这个具体看你自已的需要了
int step = 5;//一个画面容许显示的点数
List<int> listY = null;
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
pictureBox1.Refresh();
Graphics g = pictureBox1.CreateGraphics();
Random random = new Random();
listY.Add(random.Next(300));
List<Point> drawP = new List<Point>();
if (listY.Count < step)
{
for (int i = 0; i < listY.Count; i++)
{
drawP.Add(new Point(i * 60, listY[i]));
}
}
else
{
for (int i = 0; i < step; i++)
{
drawP.Add(new Point(i * 60, listY[listY.Count - i - 1]));
}
}
for (int i = 0; i < drawP.Count; i++)
{
g.FillEllipse(Brushes.Blue, drawP[i].X - 0.5f, drawP[i].Y - 0.5f, 1, 1);
}
if (drawP.Count > 1)
g.DrawLines(Pens.Red, drawP.ToArray());
g.Dispose();
System.Threading.Thread.Sleep(1000);
}