//类定义,像一般的类一样可以有方法,属性,事件,对象。
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);