📄 ddrawbox.cs
字号:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Text;
using System.Collections;
using System.ComponentModel;
namespace Custom
{
/// <summary>
/// 数据绘画
/// </summary>
public class DDrawBox : PictureBox
{
#region "属性"
#region "受保护的属性"
/// <summary>
/// 要绘制数据的位图
/// </summary>
private Bitmap _databmp;
/// <summary>
/// 背景色
/// </summary>
private Color _fillcolor;
/// <summary>
/// 前景色
/// </summary>
private Color _coordinatecolor;
/// <summary>
/// 数据点的颜色
/// </summary>
private Color _datacolor;
/// <summary>
/// 选择区域的颜色
/// </summary>
private Color _regioncolor;
/// <summary>
/// 网格颜色
/// </summary>
private Color _gridcolor;
/// <summary>
/// 选择线颜色
/// </summary>
private Color _selectlinecolor;
/// <summary>
/// 选定的x坐标,选定后会显示选定道的计数
/// </summary>
private int _selectedx;
/// <summary>
/// 选定区域的开始x坐标
/// </summary>
private int _regionstartx;
/// <summary>
/// 选定区域的结束x坐标
/// </summary>
private int _regionendx;
/// <summary>
/// 最大横坐标
/// </summary>
private int _maxX;
/// <summary>
/// 最小横坐标
/// </summary>
private int _minX;
/// <summary>
/// 最大纵坐标
/// </summary>
private int _maxY;
/// <summary>
/// 最小纵坐标
/// </summary>
private int _minY;
/// <summary>
/// 要显示的数据
/// </summary>
private int[] _data;
/// <summary>
/// 坐标画笔
/// </summary>
private Pen _pencoordinate;
/// <summary>
/// 数据画笔
/// </summary>
private Pen _pendata;
/// <summary>
/// 网格画笔
/// </summary>
private Pen _pengrid;
/// <summary>
/// 选择线画笔
/// </summary>
private Pen _penselectline;
/// <summary>
/// 坐标刷子
/// </summary>
private Brush _brushcoordinate;
/// <summary>
/// 区域刷子
/// </summary>
private Brush _brushregion;
/// <summary>
/// 数据刷子
/// </summary>
private Brush _brushdata;
/// <summary>
/// 背景刷子
/// </summary>
private Brush _brushfill;
/// <summary>
/// 数据坐标
/// </summary>
private MyCoordinate _coordinate;
/// <summary>
/// 绘画方式
/// </summary>
private bool _fill;
/// <summary>
/// 要绘画的点
/// </summary>
private Point[] _p;
/// <summary>
/// 坐标基数
/// </summary>
static private int[] nbase = {
1, 2, 5,
10, 20, 50,
100, 200, 500,
1000, 2000, 5000,
10000, 20000, 50000,
100000, 200000, 500000,
1000000, 2000000, 5000000,
10000000, 20000000, 50000000,
100000000, 200000000, 500000000};
/// <summary>
/// 数据开始的X坐标
/// </summary>
private int _datastart;
/// <summary>
/// 数据结束的X坐标
/// </summary>
private int _dataend;
/// <summary>
/// 坐标刻度x点
/// </summary>
private ArrayList _px;
/// <summary>
/// 坐标刻度y点
/// </summary>
private ArrayList _py;
/// <summary>
/// 是否画x网格
/// </summary>
private bool _paintgridx;
/// <summary>
/// 是否画y网格
/// </summary>
private bool _paintgridy;
/// <summary>
/// X标签
/// </summary>
private string _labelX;
/// <summary>
/// Y标签
/// </summary>
private string _labelY;
/// <summary>
/// 刻度标签
/// </summary>
private string _labelcalibrate;
/// <summary>
/// 绘图对象
/// </summary>
private Graphics _g;
/// <summary>
/// 感兴趣区
/// </summary>
private Hashtable _roi;
/// <summary>
/// 激活的感兴趣区
/// </summary>
private string _activatedroi;
/// <summary>
/// 激活的感兴趣区的颜色
/// </summary>
private Color _activatedcolor;
/// <summary>
/// 刻度系数
/// </summary>
private double[] _calibratecoefficient;
/// <summary>
/// 刻度显示
/// </summary>
private bool _showcalibrate;
#region "绘图对象"
/// <summary>
/// 绘图对象
/// </summary>
protected Graphics G
{
get
{
return _g;
}
}
#endregion
#endregion
#region "公共属性"
#region "背景色"
/// <summary>
/// 获取或设置背景色
/// </summary>
public Color FillColor
{
set
{
if (_fillcolor != value)
{
_fillcolor = value;
_brushfill.Dispose();
_brushfill = new SolidBrush(value);
//重画
Draw(true);
}
}
get
{
return _fillcolor;
}
}
#endregion
#region "坐标颜色"
/// <summary>
/// 获取或设置坐标颜色
/// </summary>
public Color CoordinateColor
{
set
{
if (_coordinatecolor != value)
{
_coordinatecolor = value;
//重定义颜色
_pencoordinate.Color = value;
_brushcoordinate.Dispose();
_brushcoordinate = new SolidBrush(value);
//重画
Draw(true);
}
}
get
{
return _coordinatecolor;
}
}
#endregion
#region "数据点颜色"
/// <summary>
/// 获取或设置数据点的颜色
/// </summary>
public Color DataColor
{
set
{
if (_datacolor != value)
{
_datacolor = value;
//重定义颜色
_pendata.Color = value;
_brushdata.Dispose();
_brushdata = new SolidBrush(value);
//重画
Draw(true);
}
}
get
{
return _datacolor;
}
}
#endregion
#region "选择区域颜色"
/// <summary>
/// 获取或设置选择区域的颜色
/// </summary>
public Color RegionColor
{
set
{
if (_regioncolor != value)
{
_regioncolor = value;
//重定义颜色
_brushregion.Dispose();
_brushregion = new SolidBrush(value);
//重画
Draw(true);
}
}
get
{
return _regioncolor;
}
}
#endregion
#region "网格颜色"
/// <summary>
/// 获取或设置网格的颜色
/// </summary>
public Color GridColor
{
set
{
if (_gridcolor != value)
{
_gridcolor = value;
//重定义颜色
_pengrid.Color = value;
//重画
Draw(true);
}
}
get
{
return _gridcolor;
}
}
#endregion
#region "选择线颜色"
/// <summary>
/// 获取或设置选择线的颜色
/// </summary>
public Color SelectLineColor
{
set
{
if (_selectlinecolor != value)
{
_selectlinecolor = value;
//重定义颜色
_penselectline.Color = value;
//重画
Draw(true);
}
}
get
{
return _selectlinecolor;
}
}
#endregion
#region "最大横坐标"
/// <summary>
/// 获取或设置最大横坐标
/// </summary>
public int MaxX
{
set
{
if (value != _maxX)
{
_maxX = value;
if (_maxX > 1073741824)
{
_maxX = 1073741824;
}
if (_maxX > _minX)
{
int maxdrawx = Math.Min(_dataend, _maxX);
int mindrawx = Math.Max(_datastart, _minX);
int n = maxdrawx - mindrawx + 1;
//绘画点数
if (n < 0)
{
n = 0;
}
if (_p.Length != n + 2)
{
_p = new Point[n + 2];
}
//重画
Draw(true);
}
}
}
get
{
return _maxX;
}
}
#endregion
#region "最小横坐标"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -