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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 数据点结构
/// </summary>
struct DataPoint
{
public int V;
public DateTime T;
}
private const int n = 20;//点数
private int vMax = 1;//最大值
private const int r = 6;//点半径
private DataPoint[] data = new DataPoint[n];//数据点
private Point[] points = new Point[n];//坐标点
/// <summary>
/// 添加数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < n - 1; i++)
{
data[n - i - 1] = data[n - i - 2];
}
data[0].T = DateTime.Now;
try
{
data[0].V = int.Parse(textBox1.Text);
}
catch
{
data[0].V = 0;
}
if (data[0].V > vMax)
{
vMax = data[0].V;//更新最大值
}
this.Refresh();//刷新,导致窗口重绘
}
//绘图函数
private void Form1_Paint(object sender, PaintEventArgs e)
{
for (int i=0; i < n; i++)
{
DataPoint dataPoint=data[i];
points[i].X=this.Width/n*i;
points[i].Y=this.Height-dataPoint.V*this.Height/vMax;
Rectangle rect = new Rectangle(points[i].X - r, points[i].Y - r, r + r, r + r);
e.Graphics.FillEllipse(new SolidBrush(Color.Green), rect);
e.Graphics.DrawEllipse(new Pen(Color.Red, 1), rect);
e.Graphics.DrawString(dataPoint.T.ToShortTimeString(), this.Font, new SolidBrush(Color.Black), points[i].X, this.Height -100);
}
e.Graphics.DrawLines(new Pen(Color.Red, 1), points);
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 数据点结构
/// </summary>
struct DataPoint
{
public int V;
public DateTime T;
}
private const int n = 20;//点数
private int vMax = 1;//最大值
private const int r = 6;//点半径
private DataPoint[] data = new DataPoint[n];//数据点
private Point[] points = new Point[n];//坐标点
/// <summary>
/// 添加数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < n - 1; i++)
{
data[n - i - 1] = data[n - i - 2];
}
data[0].T = DateTime.Now;
try
{
data[0].V = int.Parse(textBox1.Text);
}
catch
{
data[0].V = 0;
}
if (data[0].V > vMax)
{
vMax = data[0].V;//更新最大值
}
this.Refresh();//刷新,导致窗口重绘
}
//绘图函数
private void Form1_Paint(object sender, PaintEventArgs e)
{
for (int i=0; i < n; i++)
{
DataPoint dataPoint=data[i];
points[i].X=this.Width/n*i;
points[i].Y=this.Height-dataPoint.V*this.Height/vMax;
Rectangle rect = new Rectangle(points[i].X - r, points[i].Y - r, r + r, r + r);
e.Graphics.FillEllipse(new SolidBrush(Color.Green), rect);
e.Graphics.DrawEllipse(new Pen(Color.Red, 1), rect);
e.Graphics.DrawString(dataPoint.T.ToShortTimeString(), this.Font, new SolidBrush(Color.Black), points[i].X, this.Height -100);
}
e.Graphics.DrawLines(new Pen(Color.Red, 1), points);
}
}
}
结果图 代码过程: Form界面布局,控件:2个RadioButton, 3个button,1个chart,1个timer控件 代码区:Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using ...
int[] x = new int[20]; int[] y = new int[20]; float[] data = new float[20]; Point[] pot = new Point[20]; int i = 0; Font f = new Font("...private void Form1_Paint(object sender,...
在C#winform应用程序中,可以用GDI绘制出线条或图形。 1、在主窗体上绘制线条或图形 using (Graphics g = this.CreateGraphics()) { g.DrawLine(Pens.Blue, new Point(10, 10), new Point(100, 100)); } 2、在...
```csharp using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; ...usi...
C#在chart波形图上面添加标记标记线或标记区域 源码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using ...