Jump to content

Textbox question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
deas

deas

    Newbie

  • Members
  • Pip
  • 7 posts
Is it possible to get the software to call a function or do something when something i pasted (ctrl+v) into a textbox? Not when a user manually type text into the box, ONLY when the user pasts text into the box.

Im using VB2008

Cheers!

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You can capture keystrokes using KeyEventArgs.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
deas

deas

    Newbie

  • Members
  • Pip
  • 7 posts
Got any examples? :)

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I believe that if you create an event handler for the KeyDown event, then you may be able to use the EventArgs variable "e" to determine whether Control-V was pressed.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
bataa

bataa

    Newbie

  • Members
  • Pip
  • 3 posts
I think that should be possible. Did you try again?

#6
deas

deas

    Newbie

  • Members
  • Pip
  • 7 posts
I did think of that, and tried it. But the problem is that e.KeyCode only seems to be able to handle 1 key at the time.

My code looks like this:
Private Sub Textbox1_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Textbox1.KeyDown

        If e.KeyCode = Keys.Control Then

            If e.KeyCode = Keys.V Then

                FixPastedData()

            End If

        End If

    End Sub

I know this isnt right (since it's not working). But I have tried alot of ways but cant get it to work :/

#7
Corky

Corky

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
try this

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.Control And e.KeyCode = Keys.V Then
           FixPastedData()
        End If
End Sub