10-12-15, 03:23 AM
10-12-15, 12:13 PM
مثلا اذا اردت التراجع عن امر معين من مربع نص استخدم الكود التالي
PHP كود :
TextBox1.Undo()
10-12-15, 09:47 PM
بعتقد ان بعض الادوات تقبل تراجع مرة واحدة فاذا كان المطلوب تراجع اكثر من مرة محتاجة مكدس Stack يلي هو ما يضاف أخيرا يسحب اولا (فكرة رص الاطباق).
وفكرة Stack بيتم الاضافة ليها ب Push والسحب منها ب Pop .
وهاد رابط لموضوع (Multiple undo and redo in richtextbox - VB.NET) بعتقد فيه يلي تريده
https://social.msdn.microsoft.com/Forums...7b0795aee2
نقلت المشاركة من الرابط للتسهيل عليكم
وفكرة Stack بيتم الاضافة ليها ب Push والسحب منها ب Pop .
وهاد رابط لموضوع (Multiple undo and redo in richtextbox - VB.NET) بعتقد فيه يلي تريده
https://social.msdn.microsoft.com/Forums...7b0795aee2
نقلت المشاركة من الرابط للتسهيل عليكم
Hi,
Here is a Class that i have that i don`t remember where it came from but, it is for multiple Undo/Redo actions. It also has some other options like Clear, CanUndo, and CanRedo that is pretty handy. You can add a class to your project by clicking (Project) on the VB menu and selecting (Add Class). Then copy this code to it.
Then as an example of using the class to Undo and Redo text in a RichTextBox on your Form you would use it like this.
If you say it can`t be done then i`ll try it
Proposed as answer by .paul. _ Thursday, October 02, 2014 2:39 AM
Marked as answer by JDS404 Thursday, October 02, 2014 6:55 PM
Wednesday, October 01, 2014 9:34 PM
IronRazerz
Here is a Class that i have that i don`t remember where it came from but, it is for multiple Undo/Redo actions. It also has some other options like Clear, CanUndo, and CanRedo that is pretty handy. You can add a class to your project by clicking (Project) on the VB menu and selecting (Add Class). Then copy this code to it.
كود :
Public Class UndoRedoClass(Of T)
Private UndoStack As Stack(Of T)
Private RedoStack As Stack(Of T)
Public CurrentItem As T
Public Event UndoHappened As EventHandler(Of UndoRedoEventArgs)
Public Event RedoHappened As EventHandler(Of UndoRedoEventArgs)
Public Sub New()
UndoStack = New Stack(Of T)
RedoStack = New Stack(Of T)
End Sub
Public Sub Clear()
UndoStack.Clear()
RedoStack.Clear()
CurrentItem = Nothing
End Sub
Public Sub AddItem(ByVal item As T)
If CurrentItem IsNot Nothing Then UndoStack.Push(CurrentItem)
CurrentItem = item
RedoStack.Clear()
End Sub
Public Sub Undo()
RedoStack.Push(CurrentItem)
CurrentItem = UndoStack.Pop()
RaiseEvent UndoHappened(Me, New UndoRedoEventArgs(CurrentItem))
End Sub
Public Sub Redo()
UndoStack.Push(CurrentItem)
CurrentItem = RedoStack.Pop
RaiseEvent RedoHappened(Me, New UndoRedoEventArgs(CurrentItem))
End Sub
Public Function CanUndo() As Boolean
Return UndoStack.Count > 0
End Function
Public Function CanRedo() As Boolean
Return RedoStack.Count > 0
End Function
Public Function UndoItems() As List(Of T)
Return UndoStack.ToList
End Function
Public Function RedoItems() As List(Of T)
Return RedoStack.ToList
End Function
End Class
Public Class UndoRedoEventArgs
Inherits EventArgs
Private _CurrentItem As Object
Public ReadOnly Property CurrentItem() As Object
Get
Return _CurrentItem
End Get
End Property
Public Sub New(ByVal currentItem As Object)
_CurrentItem = currentItem
End Sub
End ClassThen as an example of using the class to Undo and Redo text in a RichTextBox on your Form you would use it like this.
كود :
Public Class Form1
Private urc As New UndoRedoClass(Of String)()
Private NoAdd As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button_Undo.Enabled = False
Button_Redo.Enabled = False
urc.AddItem(RichTextBox1.Text)
End Sub
Private Sub Button_Undo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Undo.Click
NoAdd = True
urc.Undo()
RichTextBox1.Text = urc.CurrentItem
Button_Undo.Enabled = urc.CanUndo
Button_Redo.Enabled = urc.CanRedo
NoAdd = False
End Sub
Private Sub Button_Redo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Redo.Click
NoAdd = True
urc.Redo()
RichTextBox1.Text = urc.CurrentItem
Button_Undo.Enabled = urc.CanUndo
Button_Redo.Enabled = urc.CanRedo
NoAdd = False
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
If Not NoAdd Then
urc.AddItem(RichTextBox1.Text)
Button_Undo.Enabled = urc.CanUndo
Button_Redo.Enabled = urc.CanRedo
End If
End Sub
End ClassIf you say it can`t be done then i`ll try it
Proposed as answer by .paul. _ Thursday, October 02, 2014 2:39 AM
Marked as answer by JDS404 Thursday, October 02, 2014 6:55 PM
Wednesday, October 01, 2014 9:34 PM
IronRazerz