Problem with undo delete in TextBox control

  • Thread starter Thread starter Predrag Rakic
  • Start date Start date
P

Predrag Rakic

How can be selected text in a TextBox deleted by issuing some TextBox class method or property? The goal of the deletion is that it can be undone. I have tryed to delete text with textBox.SelectedText = "", which functions as it can be expected, but can not be undoned.What is interesting, is that it functions well with RichTextBox control. Regards, Predrag.
 
..NET doesn't have a built in way of doing that.
You'll have to use PInvoke:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(System.IntPtr hWnd, int msg, int
lParam, int wParam);
private const int WM_CLEAR = 0x0303;
....
SendMessage(myTextBox.Handle, WM_CLEAR, 0, 0);

/claes

Predrag Rakic said:
How can be selected text in a TextBox deleted by issuing some TextBox
class method or property? The goal of the deletion is that it can be undone.
I have tryed to delete text with textBox.SelectedText = "", which functions
as it can be expected, but can not be undoned.What is interesting, is that
it functions well with RichTextBox control. Regards, Predrag.
 
Back
Top