Detecting a paste 'event' in a textbox


S

ssg31415926

Is there an easy way to detect when someone has pasted text into a
textbox?
 
Ad

Advertisements

C

ClayB

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

Massimo

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
 
Ad

Advertisements

S

Stoitcho Goutsev \(100\)

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);
}
 

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