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

Posted on 2005-05-09
Last Modified: 2010-04-16
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?
Question by:Jenny12345
    1 Comment
    LVL 96

    Accepted Solution

    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 run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now