[quote=引用 10 楼 u010119353 的回复:] [quote=引用 9 楼 u012592437 的回复:] 完整代码:Form1.Designer.cs namespace WindowsFormsApplication1 { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(442, 14); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(105, 21); this.textBox1.TabIndex = 0; // // button1 // this.button1.Location = new System.Drawing.Point(553, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(640, 326); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; } } Form1.cs 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); } } }
[quote=引用 9 楼 u012592437 的回复:] 完整代码:Form1.Designer.cs namespace WindowsFormsApplication1 { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(442, 14); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(105, 21); this.textBox1.TabIndex = 0; // // button1 // this.button1.Location = new System.Drawing.Point(553, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(640, 326); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; } } Form1.cs 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); } } }
完整代码:Form1.Designer.cs namespace WindowsFormsApplication1 { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(442, 14); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(105, 21); this.textBox1.TabIndex = 0; // // button1 // this.button1.Location = new System.Drawing.Point(553, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(640, 326); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; } } Form1.cs 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); } } }
[quote=引用 5 楼 u012592437 的回复:] [quote=引用 3 楼 u010119353 的回复:] [quote=引用 1 楼 u012592437 的回复:] 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); }
[quote=引用 3 楼 u010119353 的回复:] [quote=引用 1 楼 u012592437 的回复:] 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); }
[quote=引用 1 楼 u012592437 的回复:] 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); }
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); }
[quote=引用 11 楼 u012592437 的回复:] [quote=引用 10 楼 u010119353 的回复:] [quote=引用 9 楼 u012592437 的回复:] 完整代码:Form1.Designer.cs namespace WindowsFormsApplication1 { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(442, 14); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(105, 21); this.textBox1.TabIndex = 0; // // button1 // this.button1.Location = new System.Drawing.Point(553, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(640, 326); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; } } Form1.cs 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); } } }
111,097
社区成员
642,554
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧