Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Capture when a user pastes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Resolved [RESOLVED] [2005] Capture when a user pastes

    I'm trying to find the easiest way to capture when the user presses CRTL+V or right clicks and pastes inside my textbox (txtSerial).

    My end goal is to take the pasted text and turn it into an array, which I'm already doing, but the problem is my method takes the clipboard text when the user raises the TextChange event, even if their not actually pasting.

    Edit:

    Okay so I figured out how to capture the key press of CRTL + V, now I just need to figure out how to capture when the user pastes from right clicking.

    Code:
    Private Sub txtSerial1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSerial1.KeyDown
            If e.KeyCode = Keys.V And Keys.Alt Then
                'Fire!
            End If
        End Sub
    Last edited by tylerm; Mar 21st, 2007 at 03:24 PM.

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Capture when a user pastes

    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Capture when a user pastes

    That pastes the text into the textbox, I'm trying to capture the event of pasting, as in when the user does paste, I can do an If/Else statement, not to actually paste the code into the textbox, at least not right away.

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Capture when a user pastes

    I think that with a tiny modification to the example you could tell it not to paste... or at least make it look like it hasn't.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Capture when a user pastes

    You'd have to inherit the TextBox class and override the WndProc method, then trap the appropriate message(s). Exactly what message(s) you'd be looking for I don't know, but there's where you start researching.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Capture when a user pastes

    I solved my problem by adding a context menu strip to the textbox and just adding an event to that button item for Paste. It's a cheap solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width