How will you do redo and undo in textbox control?
Answer / Tarun Kumar Chaturvedi
{"In order to implement Redo and Undo functionality for a TextBox control, you can use the undo stack pattern. This involves maintaining an array or linked list of previous states (strings) that the TextBox has been in. You can then push new states onto this stack when changes are made, and pop off old states to undo those changes. To redo, simply apply the popped-off state again. Here's a simplified example using an ArrayList:
```csharp
ArrayList undoStack = new ArrayList(); // Initialize an empty undo stack
// To push a new state onto the undo stack:
undoStack.Add(textBox1.Text);
textBox1.Text = newText; // Set the TextBox's text to the new value
// To undo the last change:
if (undoStack.Count > 0)
{
textBox1.Text = (string)undoStack[undoStack.Count - 1]; // Get and set the previous state
undoStack.RemoveAt(undoStack.Count - 1); // Remove the last state from the stack
}
```
}
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the difference between vb.net and vc#.net?
Which Namespace is used to to achieve MultiThreading in .NET?
What is alias ? Is it used in .Net ?
Differentiate between managed and unmanaged code?
Explain me what is the difference between a class and an object, and how do these terms relate to each other?
What do you mean by Driver Script?
Explain me what is a design pattern and what is it for?
object is physical and class is logical..here class is not occupying any memory as our definition of class but i got a question then the class where it stores if it is not occupying any memory....
What’s different between process and application in .net?
Please explain the difference between constants and read-only variables?
What does .net stand for?
Why MVC programming model preferred?