Dieser Code ist gut geeignet als Library-Code, da man ja in so gut wie jedem Programm eine Rückwärts-Taste hat:
Aus der Formklasse (meistens) spricht man ihn so an, wenn man ihn als dll-importiert:
Um eine unendliche Speicherung hinzubekommen, einfach bei den beiden Add-Subs die Beschränkung, mit 5 als maximalen Inhalt entnehmen.
VB.NET-Quellcode
- Imports Microsoft.VisualBasic
- Public Class UndoCollection
- Public UCollection As New Collection
- Dim LastInsert As Integer = 0
- Dim content As String = ""
- 'Dim a As Integer = 0
- Public Sub Add(ByVal link As String)
- Dim result As Integer = UCollection.Count
- If result < 5 Then
- content = link
- UCollection.Add(link)
- LastInsert += 1
- 'a += 1
- End If
- End Sub
- Public Sub Remove()
- Dim result As Integer = UCollection.Count
- If 0 < result AndAlso result <= 5 Then
- UCollection.Remove(LastInsert)
- LastInsert -= 1
- 'a -= 1
- End If
- End Sub
- Public Function Undo() As String
- Dim result As Integer = UCollection.Count
- Dim value As String = ""
- Dim item As Object
- If result > 0 Then
- item = UCollection.Item(LastInsert)
- value = item.ToString
- Remove()
- End If
- Return value
- End Function
- End Class
- Public Class RedoCollection
- Public RCollection As New Collection
- Dim LastInsert As Integer = 0
- 'Dim r As Integer = 0
- Public Sub Add(ByVal link As String)
- Dim result As Integer = RCollection.Count
- If result < 5 Then
- RCollection.Add(link)
- LastInsert += 1
- 'a += 1
- End If
- End Sub
- Public Sub Remove()
- Dim result As Integer = RCollection.Count
- If 0 < result AndAlso result <= 5 Then
- RCollection.Remove(LastInsert)
- LastInsert -= 1
- 'a -= 1
- End If
- End Sub
- Public Function Redo() As String
- Dim result As Integer = RCollection.Count
- Dim value As String = ""
- Dim item As Object
- If result > 0 Then
- item = RCollection.Item(LastInsert)
- value = item.ToString
- Remove()
- End If
- Return value
- End Function
- End Class
Aus der Formklasse (meistens) spricht man ihn so an, wenn man ihn als dll-importiert:
VB.NET-Quellcode
- UndoRedoLibrary 'Namespace
- UndoRedoLibrary.UndoCollection 'Klasse UndoCollection
- UndoRedoLibrary.UndoCollection.Add(link) 'Die Sub Add (der Klasse UndoCollection) die als Wert, den zu speichernden Inhalt als String benötigt.
- UndoRedoLibrary.UndoCollection.Undo() 'Die Funktion Undo(), die den String des zuletzt hinzugefügten Objekts zurückgibt.
- UndoRedoLibrary.RedoCollection 'Klasse RedoCollection
- UndoRedoLibrary.RedoCollection.Add(link) 'Die Sub Add (der Klasse RedoCollection), die als Wert, den zu speichernden Inhalt als String benötigt.
- UndoRedoLibrary.RedoCollection.Redo() ' Die Funktion Redo(), die den String des zuletzt hinzugefügten Objekts zurückgibt.
- UndoRedoLibrary.UndoCollection.UCollection 'Das Collection-Objekt der Klasse UndoCollection.
- UndoRedoLibrary.RedoCollection.RCollection 'Das Collection-Objekt der Klasse RedoCollection.
- UndoRedoLibrary.UndoCollection.UCollection.Count 'Gibt die Anzahl der gespeicherten Inhalte als Integer zurück.
- UndoRedoLibrary.RedoCollection.RCollection.Count 'Gibt die Anzahl der gespeicherten Inhalte als Integer zurück.
Um eine unendliche Speicherung hinzubekommen, einfach bei den beiden Add-Subs die Beschränkung, mit 5 als maximalen Inhalt entnehmen.
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „pluginbauer“ ()