The normal Copy/Paste windows commands work fine in any controls, such as a TextBox.
But, what if you'd like to detect that something was pasted into a control, so that you
could do something, such as validation, *before* displaying it?
You need to subclass the control and dig into the message queue. For example,
subclass the TextBox and do something like this:
public class MyTextBox : TextBox
{
private const int WM_PASTE = 0x302;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PASTE)
OnSomethingPasted();
base.WndProc(ref m);
}
protected virtual void OnSomethingPasted()
{
//
// Override this and do something.
//
}
}
This is a simple example but should give you a starting point. In this example, we are
letting the standard behaviour (ie. the paste operation) cascade - you could
easily stop this.
from a solution provided by Neil Tonkin in Message #1212359
|