Detecting a paste 'event' in a textbox

  • Thread starter Thread starter ssg31415926
  • Start date Start date
One thing that might work for you it to try to catch the ctl+V
yourself in the KeyDown event and handle the paste yourself.

void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.V && (e.Modifiers & Keys.Control) !=
Keys.None)
{
TextBox tb = sender as TextBox;
string textToPaste = Clipboard.GetText();
tb.Paste();
e.Handled = true;
e.SuppressKeyPress = true;
Console.WriteLine("Pasted: {0}", textToPaste);
}
}

===============
Clay Burch
Syncfusion, Inc.
 
One thing that might work for you it to try to catch the ctl+V
yourself in the KeyDown event and handle the paste yourself.

But that won't intercept the user clicking on Edit->Paste...


Massimo
 
Hi,

You can do that by inherting new control from the text box control and
overriding WndProc in order to detect WM_PASTE message. Here is an example
for an overriden WndProc

private const int WM_PASTE = 0x0302;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PASTE)
{
MessageBox.Show("Paste");
}
base.WndProc(ref m);
}
 
Back
Top