110,533
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
Timer timer = new Timer();
Random random = new Random();
List<PointF> points = new List<PointF>();
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
timer.Interval = 1000 / 20;
timer.Tick += delegate { this.Invalidate(); };
timer.Start();
}
protected override void OnPaint(PaintEventArgs e)
{
const int SampleCount = 200, Min = 3000, Max = 5000;
if (points.Count < SampleCount)
{
this.points.Add(new PointF(
this.Width / (SampleCount + 1.0f) * (1 + points.Count),
this.Height / (Max - Min + 1.0f) * (random.Next(Min, Max) - Min)
));
}
if (points.Count > 1)
{
e.Graphics.DrawLines(Pens.Blue, points.ToArray());
}
}
}
int[] arr = new int[20];
private void timer1_Tick(object sender, EventArgs e)
{
Random rand = new Random();
for (int i = 0; i < 20; i++)
{
arr[i] = rand.Next(3000, 5000);
}
this.Invalidate();
}
private void DrawItems(int[] arr,Graphics g)
{
for (int i = 0; i < arr.Length; i++)
{
g.DrawString(arr[i].ToString(), this.Font, new SolidBrush(Color.Red), 0, 20 * i);
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
DrawItems(arr, e.Graphics);
}