代码编写:方志洪
E-mail:zhihongf#qq.com (请将 # 改为 @)
Blog:http://blog.intodream.com
============(由于我的空间对文章字数有限制,所以该代码分两篇公布2-1)============
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace curve
{
///
/// 实时动态曲线图
///
/// 代码编写:方志洪
/// 编写时间:2007年2月7日
/// E-Mail:zhihongf#qq.com(请将 # 改为 @)
/// BLOG:http://blog.intodream.com
///
public class CurveControl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.PictureBox picCurveShow;
private System.Windows.Forms.Label labShowView;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public CurveControl()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
private void InitializeComponent()
{
this.picCurveShow = new System.Windows.Forms.PictureBox();
this.labShowView = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// picCurveShow
//
this.picCurveShow.BackColor = System.Drawing.Color.Black;
this.picCurveShow.Dock = System.Windows.Forms.DockStyle.Fill;
this.picCurveShow.Location = new System.Drawing.Point(0, 0);
this.picCurveShow.Name = "picCurveShow";
this.picCurveShow.Size = new System.Drawing.Size(384, 264);
this.picCurveShow.TabIndex = 0;
this.picCurveShow.TabStop = false;
this.picCurveShow.Resize += new System.EventHandler(this.picCurveShow_Resize);
this.picCurveShow.DoubleClick += new System.EventHandler(this.picCurveShow_DoubleClick);
this.picCurveShow.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picCurveShow_MouseMove);
this.picCurveShow.MouseLeave += new System.EventHandler(this.picCurveShow_MouseLeave);
//
// labShowView
//
this.labShowView.AutoSize = true;
this.labShowView.BackColor = System.Drawing.Color.Black;
this.labShowView.ForeColor = System.Drawing.Color.Red;
this.labShowView.Location = new System.Drawing.Point(192, 96);
this.labShowView.Name = "labShowView";
this.labShowView.Size = new System.Drawing.Size(42, 17);
this.labShowView.TabIndex = 1;
this.labShowView.Text = "label1";
this.labShowView.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labShowView.Visible = false;
//
// CurveControl
//
this.Controls.Add(this.labShowView);
this.Controls.Add(this.picCurveShow);
this.Name = "CurveControl";
this.Size = new System.Drawing.Size(384, 264);
this.Load += new System.EventHandler(this.CurveControl_Load);
this.ResumeLayout(false);
}
#endregion
#region 曲线数据定义
///
/// 定义曲线窗体标题
///
private string title = "方志洪曲线代码测试DEMO";
///
/// 定义曲线标题颜色
///
private Color titleColor = Color.Yellow;
///
/// 定义是否显示系统时间
///
private bool showTime = true;
///
/// 定义显示系统时间颜色
///
private Color showTimeColor = Color.Red;
///
/// 定义坐标零点向右偏移量
///
private float coordinate = 50F;
///
/// 定义曲线Y轴最大值
///
private float yMaxValue = 100F;
///
/// 定义曲线Y轴最大值提示文字
///
private string yMaxString = "最大值:";
///
/// 定义曲线Y轴最小值
///
private float yMinValue = 0F;
///
/// 定义曲线Y轴最小值提示文字
///
private string yMinString = "最小值:";
///
/// 定义曲线Y轴正常值(上限)
///
private float yUpper = 70F;
///
/// 定义曲线Y轴正常值(上限)提示文本
///
private string yUpperString = "上限:";
///
/// 定义曲线Y轴正常值(下限)
///
private float yLower = 20F;
///
/// 定义曲线Y轴正常值(下限)提示文本
///
private string yLowerString = "下限:";
///
/// 定义曲线正常值上下限线段颜色
///
private Color yUpperAndLowerColor = Color.Lime;
///
/// 定义曲线正常值上下限线段宽度
///
private float yUpperAndLowerPenWidth = 1F;
///
/// 定义背景颜色
///
private Color backGroundColor = Color.Black;
///
/// 定义是否滚动网格线
///
private bool removeGrid = true;
///
/// 定义背景网格线颜色
///
private Color gridColor = Color.DarkGreen;
///
/// 定义背景网格文字颜色
///
private Color gridForeColor = Color.Yellow;
///
/// 定义背景网格(分隔线)宽度
///
private float gridCompart = 1F;
///
/// 定义背景网格文字大小
///
private float gridFontSize = 9;
///
/// 定义背景网格线画笔宽度
///
private float gridPenWidth = 1F;
///
/// 定义背景网格线单元格宽度
///
private float gridWidth = 10F;
///
/// 定义背景网格线单元格高度
///
private float gridHeight = 30F;
///
/// 定义曲线颜色
///
private Color curveColor = Color.White;
///
/// 定义曲线画笔宽度
///
private float curvePenWidth = 1;
///
/// 定义曲线移动距离
///
private int curveRemove = 1;
///
/// 定义数值节点正方形宽度
///
private float rectangleWidth = 1F;
///
/// 定义正方形颜色
///
private Color rectangleColor = Color.White;
///
/// 定义显示节点数值鼠标X,Y轴容差精度
///
private float xYPrecision = 4F;
///
/// 曲线节点数据最大存储量
///
private int maxNote = 1000;
#endregion
#region 公共属性
///
/// 定义曲线窗体标题
///
public string CarveTitle
{
get
{
return this.title;
}
set
{
this.title = value;
}
}
///
/// 定义标题颜色
///
public Color CarveTitleColor
{
get
{
return this.titleColor;
}
set
{
this.titleColor = value;
}
}
///
/// 定义是否显示系统时间
///
public bool CarveShowTime
{
get
{
return this.showTime;
}
set
{
this.showTime = value;
}
}
///
/// 定义显示系统时间颜色
///
public Color CarveShowTimeColor
{
get
{
return this.showTimeColor;
}
set
{
this.showTimeColor = value;
}
}
///
/// 定义坐标零点向右偏移量
///
public float CarveCoordinate
{
get
{
return this.coordinate;
}
set
{
this.coordinate = value;
}
}
///
/// 定义曲线Y轴最大值
///
public float CarveYMaxValue
{
get
{
return this.yMaxValue;
}
set
{
this.yMaxValue = value;
}
}
///
/// 定义曲线Y轴最大值提示文字
///
public string CarveYMaxString
{
get
{
return this.yMaxString;
}
set
{
this.yMaxString = value;
}
}
///
/// 定义曲线Y轴最小值
///
public float CarveYMinValue
{
get
{
return this.yMinValue;
}
set
{
this.yMinValue = value;
}
}
///
/// 定义曲线Y轴最小值提示文字
///
public string CarveYMinString
{
get
{
return this.yMinString;
}
set
{
this.yMinString = value;
}
}
///
/// 定义曲线Y轴正常值(上限)
///
public float CarveYUpper
{
get
{
return this.yUpper;
}
set
{
this.yUpper = value;
}
}
///
/// 定义曲线Y轴正常值(上限)提示文本
///
public string CarveYUpperString
{
get
{
return this.yUpperString;
}
set
{
this.yUpperString = value;
}
}
///
/// 定义曲线Y轴正常值(下限)
///
public float CarveYLower
{
get
{
return this.yLower;
}
set
{
this.yLower = value;
}
}
///
/// 定义曲线Y轴正常值(下限)提示文本
///
public string CarveYLowerString
{
get
{
return this.yLowerString;
}
set
{
this.yLowerString = value;
}
}
///
/// 定义曲线正常值上下限线段颜色
///
public Color CarveYUpperAndLowerColor
{
get
{
return this.yUpperAndLowerColor;
}
set
{
this.yUpperAndLowerColor = value;
}
}
///
/// 定义曲线正常值上下限线段宽度
///
public float CarveYUpperAndLowerPenWidth
{
get
{
return this.yUpperAndLowerPenWidth;
}
set
{
this.yUpperAndLowerPenWidth = value;
}
}
///
/// 定义背景颜色
///
public Color CarveBackGroundColor
{
get
{
return this.backGroundColor;
}
set
{
this.backGroundColor = value;
}
}
///
/// 定义是否滚动网格线
///
public bool CarveRemoveGrid
{
get
{
return this.removeGrid;
}
set
{
this.removeGrid = value;
}
}
///
/// 定义背景网格线颜色
///
public Color CarveGridColor
{
get
{
return this.gridColor;
}
set
{
this.gridColor = value;
}
}
///
/// 定义背景网格文字颜色
///
public Color CarveGridForeColor
{
get
{
return this.gridForeColor;
}
set
{
this.gridForeColor = value;
}
}
///
/// 定义背景网格(分隔线)宽度
///
public float CarveGridCompart
{
get
{
return this.gridCompart;
}
set
{
this.gridCompart = value;
}
}
///
/// 定义背景网格文字大小
///
public float CarveGridFontSize
{
get
{
return this.gridFontSize;
}
set
{
this.gridFontSize = value;
}
}
///
/// 定义背景网格线画笔宽度
///
public float CarveGridPenWidth
{
get
{
return this.gridPenWidth;
}
set
{
this.gridPenWidth = value;
}
}
///
/// 定义背景网格线单元格宽度
///
public float CarveGridWidth
{
get
{
return this.gridWidth;
}
set
{
this.gridWidth = value;
}
}
///
/// 定义背景网格线单元格高度
///
public float CarveGridHeight
{
get
{
return this.gridHeight;
}
set
{
this.gridHeight = value;
}
}
///
/// 定义曲线颜色
///
public Color CarveCurveColor
{
get
{
return this.curveColor;
}
set
{
this.curveColor = value;
}
}
///
/// 定义曲线画笔宽度
///
public float CarveCurvePenWidth
{
get
{
return this.curvePenWidth;
}
set
{
this.curvePenWidth = value;
}
}
///
/// 定义曲线移动距离
///
public int CarveCurveRemove
{
get
{
return this.curveRemove;
}
set
{
this.curveRemove = value;
}
}
///
/// 定义数值节点正方形宽度
///
public float CarveRectangleWidth
{
get
{
return this.rectangleWidth;
}
set
{
this.rectangleWidth = value;
}
}
///
/// 定义正方形颜色
///
public Color CarveRectangleColor
{
get
{
return this.rectangleColor;
}
set
{
this.rectangleColor = value;
}
}
///
/// 定义显示节点数值鼠标X,Y轴容差精度
///
public float CarveXYPrecision
{
get
{
return this.xYPrecision;
}
set
{
this.xYPrecision = value;
}
}
///
/// 曲线节点数据最大存储量
///
public int CarveMaxNote
{
get
{
return this.maxNote;
}
set
{
this.maxNote = value;
}
}
#endregion
#region 全局变量
///
/// 背景方格移动量
///
private float gridRemoveX = 1;
///
/// 鼠标X,Y 坐标值,及该点坐标记录值、记录时间(数组)
///
private CoordinatesValue[] noteMessages;
///
/// 当前鼠标 X,Y坐标记录数组下标值
///
private int noteNow = 0;
///
/// 系统上次读取的值
///
private float lastTimeValue =0F;
///
/// 系统窗体高度临时值,用于窗体变形时刷新数组坐标。
///
private int lastTimeSystemWindowHeight = 0;
///
/// 系统窗体宽度临时值,用于窗体变形时刷新数组坐标。
///
private int lastTimeSystemWindowWidth = 0;
#endregion