Reseting VB form to original state....

Discussion in 'Programming' started by Jamie1987, Apr 16, 2010.

  1. #1
    Hi all, i was wondering if you'd help me please.

    I'm creating an application in VB whereby I have plenty of radio buttons, textboxes, checkboxes, pictureboxes etc. The user can move pictureboxes around the screen etc, however I would my reset button to reset the form. I am working in Microsoft Visual studio 2008.

    I was wondering if someone knew how I could reset the whole form to it's original state, I.E so it is exactly the same apoperance like when I opened the file?

    Many thanks
     
    Jamie1987, Apr 16, 2010 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    I would advise using the memento design pattern so you have "undo" functionality built in.
     
    ccoonen, Apr 16, 2010 IP
  3. Jamie1987

    Jamie1987 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok thanks. any idea how i go about this? There's not too much online about it.
     
    Jamie1987, Apr 17, 2010 IP
  4. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Its a programming technique. Store every action into a collection of actions. Make sure every action is a base class or interface IAction. Then everything the user does, throw it on the list/collection of actions, then do the action of the last item on the list. Now you have an ordered list of specific actions the user did, and you can go back and forth or even all the way to the beginning but undoing all actions backwards. I advise getting the Head First Design Patterns book :)
     
    ccoonen, Apr 17, 2010 IP
  5. Keppy

    Keppy Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Example

    sub origState
    radio1.value = "T"
    radio2.value = "T"
    end sub

    Once you need the restore the orig value just call the sub origState
     
    Keppy, Apr 18, 2010 IP
  6. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ccoonen has stated the commonly used method for this purpose. As he also stated clearly, it is better to have a little idea on design patters for this.

    See Design Patterns Tutorial. Though the codes are C#, it will be easier for you to understand the logic.
    You may also see these video tutorials. See 15th tutorial.
     
    NeoCambell, Apr 18, 2010 IP