I suggest using a collection class like an array list. create a class to hold the information you wish to store (position and color) and then everytime this changes, add another item to the list:
example:
// This class will implement an UNDO
public class UndoCLASS
{
// use an array list instead of a stack so that you can list all elements.
private System.Collections.ArrayList UndoStack = new ArrayList();
public UndoCLASS()
{
}
----------------------
----------------------
// FUNCTION: PUSH
// PURPOSE: To add items to the undo list
----------------------
public void Push(System.Drawing.Rectangle rectangle,System.Drawing.Color color)
{
StorageCLASS NewItem = new StorageCLASS();
NewItem.rectangle = rectangle;
NewItem.color = color;
UndoStack.Add(NewItem);
}
----------------------
----------------------
// FUNCTION: Pop
// PURPOSE: To get last item added to the list
----------------------
public void Pop(ref System.Drawing.Rectangle rectangle,System.Drawing.Color color)
{
StorageCLASS OldItem = ((StorageCLASS)UndoStack[UndoStack.Count-1]);
rectangle = OldItem.rectangle;
color = OldItem.color;
UndoStack.RemoveAt(UndoStack.Count-1);
}
----------------------
----------------------
// FUNCTION: ListStack
// PURPOSE: To list stack into a combo box
----------------------
public void ListStack(ref System.Windows.Forms.ComboBox combo)
{
StorageCLASS ListItem = new StorageCLASS();
combo.Items.Clear();
for(int t=UndoStack.Count-1;t>-1;t--)
{
ListItem = ((StorageCLASS)UndoStack[t]);
combo.Items.Add("[" + ListItem.rectangle.Left.ToString() + "," + ListItem.rectangle.Top.ToString() + "," + ListItem.rectangle.Width.ToString() + "," + ListItem.rectangle.Height.ToString() + "];[" + ListItem.color.ToString() + "]");
}
}
----------------------
}
// simple storage class for storing the rectangle and color
public class StorageCLASS
{
private System.Drawing.Rectangle lRect = new Rectangle();
private System.Drawing.Color lColor = new Color();
public StorageCLASS()
{
}
public System.Drawing.Rectangle rectangle
{
set
{
lRect = value;
}
get
{
return lRect;
}
}
public System.Drawing.Color color
{
set
{
lColor = value;
}
get
{
return lColor;
}
}
}
Enjoy.
Chi
"They mostly come at night...mostly"