先建一个类,类中有两个变量作为坐标值
public class remtbpoint //remtbpoint 类(用来记忆某对象坐标)
{
private int rpointline;
private int rpointcol;
{
get { return rpointline; }
set { rpointline = value; }
}
public int RPointcol
{
get { return rpointcol; }
set { rpointcol = value; }
}
}
在主程序中定义arrayList
ArrayList rembtpointLinst = new ArrayList();
在子程序中添加坐标值到arrayList中和从arrayList中取出值
View Code
很简单,但很实用,呵呵
1 private void rempoint(int line,int col) //记忆子程序,实例化后,赋值,加到arrayList中
2 {
3 remtbpoint r1 = new remtbpoint();
4 r1.RPointLine = line;
5 r1.RPointcol = col;
6 rembtpointLinst.Add(r1);
7 }
8
9
10 private void button1_Click(object sender, EventArgs e)//从记忆的arrayList中取出值,并动态删除最后一个arrayList元素
11 {
12 int x = rembtpointLinst.Count;//直接取最末元素
13 if (x >= 1)
14 {
15 remtbpoint r3 = rembtpointLinst[x - 1] as remtbpoint;//-------对于取数组列表中某元素太难,用这个方法极好用
16 //do...(r3.RPointLine, r3.RPointcol);这里就可以把arrayList元素对应的坐标值传给其它子程序使用了.
17 rembtpointLinst.RemoveAt(x - 1);
18 }
19 }