How will you do redo and undo in textbox control?



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

Post New Answer

More Dot Net General Interview Questions

What is the difference between vb.net and vc#.net?

1 Answers  


Which Namespace is used to to achieve MultiThreading in .NET?

1 Answers  


What is alias ? Is it used in .Net ?

1 Answers   MCN Solutions,


Differentiate between managed and unmanaged code?

1 Answers  


Explain me what is the difference between a class and an object, and how do these terms relate to each other?

1 Answers  


What do you mean by Driver Script?

1 Answers   TCS,


Explain me what is a design pattern and what is it for?

1 Answers  


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....

1 Answers   Infotech, Wipro,


What’s different between process and application in .net?

1 Answers  


Please explain the difference between constants and read-only variables?

1 Answers  


What does .net stand for?

1 Answers  


Why MVC programming model preferred?

1 Answers  


Categories