110,537
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
List<Point> Points = new List<Point>();
Bitmap OrgBmp = null;
int Start = 0;
Random R = new Random();
PictureBox PB = new PictureBox();
public Form1()
{
InitializeComponent();
PB.Parent = this;
PB.Dock = DockStyle.Fill;
OrgBmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
using (Graphics G = Graphics.FromImage(OrgBmp))
{
G.Clear(Color.Black);
G.DrawString("随机曲线图", this.Font, Brushes.Green, new PointF(0, 0));
}
PB.Image = OrgBmp;
Timer T = new Timer();
T.Interval = 100;
T.Tick += new EventHandler(T_Tick);
T.Enabled = true;
}
void T_Tick(object sender, EventArgs e)
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
Points.Add(new Point(Start ++*5, 100 + 50 - R.Next(50 * 2)));
if (Points.Count > 1)
using (Graphics G = Graphics.FromImage(CacheBmp))
G.DrawCurve(Pens.Red, Points.ToArray());
PB.Image = CacheBmp;
}
}
}