Problem with undo delete in TextBox control

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

Claes Bergefall

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top