--自己格式化
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 HslnDatabase
{
public partial class Form1 : Form
{
private Timer timer;
private List<int> points;
private int timeOffset;
public Form1()
{
InitializeComponent();
// 初始化定时器
timer = new Timer();
timer.Interval = 1000; // 每秒钟绘制一次曲线
timer.Tick += Timer_Tick;
// 初始化PictureBox
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.BorderStyle = BorderStyle.FixedSingle;
// 初始化曲线点集合和时间偏移量
points = new List<int>();
timeOffset = 0;
// 启动定时器
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
// 生成一个随机的心跳频率
Random random = new Random();
int newPoint = random.Next(60, 140);
// 添加新的心跳频率数据到集合中
points.Add(newPoint);
// 如果数据点数量超过60秒,则移除最早的数据点
if (points.Count > 60)
{
points.RemoveAt(0);
timeOffset++;
}
// 重绘PictureBox
pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// 绘制心电图曲线
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Red);
int startX = 0;
if (points.Count > 0)
{
int startY = pictureBox1.Height - points[0] - 10;
for (int i = 0; i < points.Count - 1; i++)
{
int x1 = startX + i * 10;
int y1 = pictureBox1.Height - points[i] - 10;
int x2 = startX + (i + 1) * 10;
int y2 = pictureBox1.Height - points[i + 1] - 10;
g.DrawLine(pen, x1, y1, x2, y2);
}
}
// 绘制纵坐标刻度线和标签
Font font = new Font("Arial", 8);
Brush brush = Brushes.Black;
for (int i = 0; i <= pictureBox1.Height; i += 20)
{
g.DrawLine(pen, startX, i, startX + 5, i);
g.DrawString((pictureBox1.Height - i - 10).ToString(), font, brush, startX + 10, i - font.Height / 2);
}
// 绘制横坐标刻度线和标签
int labelInterval = 10;
int maxTime = 60;
for (int i = 0; i <= maxTime; i += labelInterval)
{
int x = startX + i * 10;
g.DrawLine(pen, x, pictureBox1.Height, x, pictureBox1.Height - 5);
g.DrawString((i + timeOffset).ToString(), font, brush, x - 5, pictureBox1.Height - font.Height);
}
}
}
}


