111,120
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication231
{
public partial class Form1 : Form
{
PictureBox PB = new PictureBox();
Bitmap Bmp = null;
List<int> Ys = new List<int>();
Random R = new Random();
public Form1()
{
InitializeComponent();
PB.Parent = this;
PB.Dock = DockStyle.Fill;
this.ClientSize = new Size(300+25, 300);
Bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
Timer T = new Timer();
T.Interval = 100;
T.Tick += new EventHandler(T_Tick);
T.Enabled = true;
}
void T_Tick(object sender, EventArgs e)
{
Ys.Add(R.Next(5000) - 5000 / 2);
if (Ys.Count < 2)
return;
int[] Temp =Ys.ToArray();
Array .Sort (Temp );
double XS = (Bmp.Width - 25) * 1.0 / Ys.Count;
double YS = (Bmp.Height)*1.0 / (Temp[Temp.Length -1]*2) ;
using (Graphics G = Graphics.FromImage(Bmp))
{
G.Clear(Color.Black);
G.DrawLine(Pens.White, new Point(0, Bmp.Height / 2), new Point(Bmp.Width, Bmp.Height / 2));
G.DrawLine(Pens.White, new Point(25, 0), new Point(25, Bmp.Height));
List<PointF> Points = new List<PointF>();
for (int i = 0; i < Ys.Count; i++)
{
Points.Add(new PointF((float)(i * XS + 25), (float)(Ys[i] * YS) + Bmp.Height / 2));
}
G.DrawCurve(Pens.Red, Points.ToArray());
}
PB.Image = Bmp;
}
}
}