Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Detecting a paste 'event' in a textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ssg31415926 - 05 Feb 2007 17:23 GMT
Is there an easy way to detect when someone has pasted text into a
textbox?
ClayB - 06 Feb 2007 02:02 GMT
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.
Massimo - 06 Feb 2007 08:23 GMT
> 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
Stoitcho Goutsev (100) - 06 Feb 2007 15:40 GMT
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);
 }

Signature

HTH
Stoitcho Goutsev (100)

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.