.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

copy/paste text box

0 REPLIES 0
Reply
Message 1 of 1
cadcamm99
600 Views, 0 Replies

copy/paste text box

I put in a copy/paste routine for a text box but it keeps pasting the text twice when I do cntrl+v. Any ideas why?

 

Private Sub tbPartNo02_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbPartNo02.KeyPress
        Dim KeyAscii As Integer = Asc(e.KeyChar)
        Dim byt As Byte = Convert.ToByte(e.KeyChar)

 

        If byt = 24 Then 'Ctrl+X number in alphabet
            myCut()
        ElseIf byt = 3 Then 'Ctrl+C number in alphabet
            myCopy()
        ElseIf byt = 22 Then 'Ctrl+V number in alphabet
            myPaste()
        Else
            Select Case KeyAscii
                Case 48 To 57 'Accept numbers 0-9
                    e.KeyChar = e.KeyChar
                Case 65 To 90 'Accept letters A-B
                    e.KeyChar = e.KeyChar
                Case 97 To 122 'Accept letters a-b
                    e.KeyChar = UCase(e.KeyChar)
                Case 45 'Accept dashes
                    e.KeyChar = e.KeyChar
                Case 8 'Accept backspace
                    e.KeyChar = e.KeyChar
                Case Else
                    e.Handled = True
            End Select
        End If
    End Sub

 

Private Sub myPaste()
        'Check if active control is a textbox
        If TypeOf Me.ActiveControl Is TextBox Then
            'Associate active control to textbox
            Dim SelectedTextbox As TextBox = Me.ActiveControl

            'Check if text in clipboard is text
            If Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
                'SelectedTextbox.Paste() 'Past text to active textbox
                'SelectedTextbox.SelectedText = Clipboard.GetText
                SelectedTextbox.SelectedText = CType(Clipboard.GetDataObject.GetData(DataFormats.Text), String)
            End If
        End If
    End Sub

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost