[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

How to keep track of pressed toggle buttons of the toolbar if I have an undo button on the toolbar?

I have a toolbar control that has about 5 toggle buttons and one of the buttons is an undo button.  (Undo buttons is a regular push button)  The buttons on the toolbar perform drawing fucntions like inverting an image or brighting an image etc. after each image change I store the state of that image to an arraylist like this..
                private ArrayList PreviousImages = new ArrayList();      
                Bitmap y = new Bitmap(imageBox.Image);
so on my undo button click I
      PreviousImages.RemoveAt(PreviousImages.Count - 1);
                imageBox.Image = (Bitmap) PreviousImages[PreviousImages.Count - 1];

Now the problem is on the toggle buttons when I undo the buttons still look pressed and I don't have a way of knowing which change I just have undone.  what is the best approach on solving this problem?  Is there a way to add another column to my arraylist and keep track of which toolbar button that change belongs to?
1 Solution
Bob LearnedCommented:
When you click on undo, you want to undo a previous change.  

You can store objects in a Stack, so you could do something like this:

private class UndoAction
 public Image Image;
 public ToolbarButton Button;

 public void UndoAction(Image image, ToolbarButton button)
    this.Image = image
    this.Button = button

private Stack undo = new Stack();    
undo.Push(new UndoAction(imageBox.Image, <toolbar Button goes here>));

UndoAction action = undo.Pop();
imageBox.Image = undo.Image;


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now