PC Review


Reply
Thread Tools Rate Thread

Detecting a paste 'event' in a textbox

 
 
ssg31415926
Guest
Posts: n/a
 
      5th Feb 2007
Is there an easy way to detect when someone has pasted text into a
textbox?

 
Reply With Quote
 
 
 
 
ClayB
Guest
Posts: n/a
 
      6th Feb 2007
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.


 
Reply With Quote
 
Massimo
Guest
Posts: n/a
 
      6th Feb 2007
"ClayB" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...

> 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

 
Reply With Quote
 
Stoitcho Goutsev \(100\)
Guest
Posts: n/a
 
      6th Feb 2007
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);
}


--
HTH
Stoitcho Goutsev (100)
"ssg31415926" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there an easy way to detect when someone has pasted text into a
> textbox?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting Paste in WebBrowser control nagar@community.nospam Microsoft C# .NET 1 25th Jun 2008 01:09 PM
TextBox Paste event DaveL Microsoft C# .NET 2 28th Apr 2008 07:02 PM
How to raise an event of button (click event) from textbox's onkeydown event? ABC Microsoft Dot NET Framework Forms 2 25th Jul 2006 11:19 AM
Detecting Symbols in Textbox Joseph Microsoft Excel Programming 1 14th Nov 2004 04:48 PM
Detecting which key was pressed on a textbox Simon Harvey Microsoft ASP .NET 1 22nd Jun 2004 04:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.