Form1.cs
上传用户:tonyxiao
上传日期:2009-05-16
资源大小:39k
文件大小:2k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace 实时曲线绘制
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public Point[] ptlist;//存放点的数组
- Random rm = new Random();//随机数产生器
- Timer mytimer = new Timer();//定时器
- //窗口加载时调用
- private void Form1_Load(object sender, EventArgs e)
- {
- //设置控件的样式和行为,以减少图像的闪烁
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
- this.SetStyle(ControlStyles.ResizeRedraw, true);
- this.UpdateStyles();
- //实例化数组
- ptlist = new Point[this.pictureBox1.Width/5];
- Point pt;
- for (int i = 0; i < this.pictureBox1.Width/5; i++)
- {
- pt = new Point();
- pt.X =5* i;//5个像素绘制一个点
- pt.Y = rm.Next() % this.pictureBox1.Height;
- ptlist[i] = pt;
- }
-
- }
- draw drawtest = new draw();//创建类 draw 的实例
- private void button1_Click(object sender, EventArgs e)
- {
- //动态添加一个定时器
- this.timer1.Enabled = true;//可以使用
- this.timer1.Interval = 100;//定时时间为100毫秒
- this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
-
- this.timer1.Start();//启动定时器
- }
-
- private void timer1_Tick(object sender, EventArgs e)
- {
- //调用绘图函数,这里的参数可以根据不同的测量给定不同的实参
- drawtest.DrawLineS(Color.Blue, 1200, 600, pictureBox1, ptlist);
-
- }
- }
- }