Hi,
I am writing a simple drawing application where the user places a series of data points on the screen.
Each of the data points has a number of properties as defined by :
The whole drawing is defined by a collection of data points so I have :Code:<Serializable()> _ Public Class objDataPoint Public Location As Point Public Moveable As Boolean Public Time As Single Public Power As Single Public Selected As Boolean Public Sub New(ByVal Location As Point, ByVal Moveable As Boolean, ByVal Time As Single, ByVal Power As Single, ByVal Selected As Boolean) 'Set the attributes Me.Location = Location Me.Moveable = Moveable Me.Time = Time Me.Power = Power Me.Selected = Selected End Sub End Class
and as the user adds a data point to the drawing canvas I just add another member to the collection.Code:Private colDataPoints As New Collection
Now I want to implement an Undo function and I am not sure how to do this.
My first idea was to create another collection and have a collection of collections but I could not get this to work.
I have done a lot of searching and come up with a number of suggestions including serialization and using a Stack object.
This is my attempt at using the Stack object but it doesn't work either.
I have been scratching my head on this all day so any help is appreciated.Code:Private HistoryStack As New Stack Private Sub SaveUndoInformation() HistoryStack.Push(colDataPoints) tsbUndo.Enabled = True End Sub Private Sub tsbUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbUndo.Click 'Remove all current data points. colDataPoints.Clear() 'Make sure that no point is currently selected. m_intSelectedDataPoint = -1 'Extract the data. Dim colTemp As New Collection colTemp = HistoryStack.Pop colDataPoints = HistoryStack.Pop If HistoryStack.Count = 0 Then tsbUndo.Enabled = False 'Force the display area to redraw after all new data points have been loaded. picCanvas.Invalidate() End Sub




Reply With Quote