c#做一个类似心电图效果的程序,从左往右100ms描一个点,连线,就像用笔在画线一样,到达一定宽度 100
c#做一个类似心电图效果的程序,从左往右100ms描一个点,连线,就像用笔在画线一样,到达一定宽度,再从头画,这时每描一个点,就先擦出这一列的点。...
c#做一个类似心电图效果的程序,从左往右100ms描一个点,连线,就像用笔在画线一样,到达一定宽度,再从头画,这时每描一个点,就先擦出这一列的点。
展开
2个回答
展开全部
//说明,最好将pictureBox_board的背景色设置为黑色,timer1时间间隔设为100ms
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace heartBeat
{
public partial class Form1 : Form
{
int i = 0;
int y0 = 0; //上一个Y
static int Xinterval = 10; //水平间隔10像素
static int Horizontal = 50; //水平方向总点数50
static int Vertical = 100; //垂直200像素
struct line
{
int x1, y1, x2, y2;
public void Move(int x1, int y1, int x2, int y2)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public void paint(Graphics g)
{
g.DrawLine(Pens.Yellow, x1, y1, x2, y2);
g.SmoothingMode = SmoothingMode.AntiAlias;
}
}
struct point
{
public int x, y;
public void Move(int x, int y)
{
this.x = x;
this.y = y;
}
public void paint(Graphics g)
{
g.DrawEllipse(Pens.Red, x - 1, y - 1, 3, 3);
g.SmoothingMode = SmoothingMode.AntiAlias;
}
}
line[] l = new line[Horizontal];
point p = new point();
public Form1()
{
InitializeComponent();
}
Random r = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
draw(r.Next(Vertical));
}
void draw(int y)
{
int ii = i % Horizontal;
y += 50;
l[ii].Move(ii * Xinterval, y0, (ii + 1) * Xinterval, y);
p.Move((ii + 1) * Xinterval, y);
textBox_points.Text += p.x.ToString() + " , " + p.y.ToString() + Environment.NewLine;
i++;
pictureBox_board.Invalidate();
y0 = y;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
for (int i = 0; i < Horizontal; i++)
{
l[i].paint(e.Graphics);
}
p.paint(e.Graphics);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询