//类定义,像一般的类一样可以有方法,属性,事件,对象。
public class pChart
{
public Object crtObj;
public ChartType crtType;
public DataSet crtDataSet;
public string crtTitle = "";
public int crtMinNumber = 0;
public int crtMaxNumber = 0;
public int crtScale = 0;
public string crtUnit = "";
public pChart(string chartTitle,Object chartObject, ChartType chartType, DataSet chartDataSet, int minNumber, int maxNumber, int scale,string unit)
{
crtObj = chartObject;
crtType = chartType;
crtDataSet = chartDataSet;
crtTitle = chartTitle;
crtMinNumber = minNumber;
crtMaxNumber = maxNumber;
crtScale = scale;
crtUnit = unit;
}
}
//集合类,为之前的类提供add,remove方法。
public class AChart : System.Collections.CollectionBase
{
public AChart()
{ }
public void AddChart(string chartTitle, Object chartObject, ChartType chartType, DataSet chartDataSet, int minNumber, int maxNumber, int scale,string unit)
{
List.Add(new pChart(chartTitle,chartObject,chartType,chartDataSet,minNumber,maxNumber,scale,unit));
}
public void RemoveChart(int index)
{
if (index > Count - 1 || index < 0)
{
MessageBox.Show("Index not valid!");
}
else
{
List.RemoveAt(index);
}
}
public AChart Item
{
get
{
return this;
}
}
[System.Runtime.CompilerServices.IndexerName("item")]
public pChart this[int index]
{
get
{
return (pChart)List[index];
}
}
}
//实例化集合类
private static AChart chart = new AChart();
//每次都可以在方法或事件里添加集合类的子类,就像arraylist动态数组一样。
chart.AddChart(chartTitle, control, chartType, dataSet, minNumber, maxNumber, scale,unit);
chart.Item[index].chartTitle=textBox1.Text;
chart.RemoveChart(index);
本文介绍了一个用于图表绘制的类库设计,主要包括一个基础图表类`pChart`和一个图表集合类`AChart`。`pChart`类定义了图表的基本属性如标题、类型等,并提供了构造函数初始化这些属性;`AChart`类则实现了图表的增删功能,方便用户动态管理多个图表。
1万+

被折叠的 条评论
为什么被折叠?



