Results 1 to 7 of 7

Thread: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box (Text1.Text)?

    any idea please!

    I found something, is correct ?
    Code:
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    
    'Ctrl + A
    If KeyCode = 65 And Shift = 2 Then '
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
    KeyAscii = 0
    End If
    
    
    'Ctrl + C
    If KeyCode = 67 And Shift = vbCtrlMask Then
    Clipboard.Clear
    Clipboard.SetText Text1.SelText
    End If
    
    
    'Ctrl + V
    ....
    
    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    You don't have to write any code for this.

    If you select the text and right mouse click, there is a default popup menu that contains Cut/Copy/Paste/Delete already there for you.

  3. #3
    Addicted Member reacen's Avatar
    Join Date
    Jul 2009
    Location
    c:\windows\system32\gdi32.dll
    Posts
    243

    Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    Ctrl+C; Ctrl+V; Ctrl+X; work fine without any codes in a Text1 on vb6...
    The only thing you'll need is this: (For Ctrl+A).

    Code:
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    
        If KeyCode = 65 And Shift = 2 Then
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End If
    
    End Sub
    DoEvents

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    Thanks. It important.
    >>Ctrl+C; Ctrl+V; Ctrl+X; work fine without any codes in a Text1 on vb6...


    But,
    (1) Shift = 2 ?

    (2) 'Ctrl + A' as same as Ctrl + a 97, is correct ?

    Code:
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    
        If KeyCode = 65 And Shift = 2 Then '65 = A"
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End If
    
        If KeyCode = 97 And Shift = 2 Then '97 = a"
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End If
    
    
    End Sub

  5. #5
    Addicted Member reacen's Avatar
    Join Date
    Jul 2009
    Location
    c:\windows\system32\gdi32.dll
    Posts
    243

    Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    No need to do that. Just keep the "65".

    (1) Shift = 2 Is for both "Ctrls".
    (2) The keyboard sends the "65 KeyCode" when you press "a" whether its "A" Capital or not, so i don't think its gonna work with (If KeyCode = 97 And Shift = 2 Then). Just keep the first one.
    DoEvents

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    Code:
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
       'This is critical - KeyPreview MUST be set to True
        If (Shift And vbCtrlMask) = vbCtrlMask And KeyCode = vbKeyA Then
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End If
    End Sub

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?

    Quote Originally Posted by Hack View Post
    Code:
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
       'This is critical - KeyPreview MUST be set to True
        If (Shift And vbCtrlMask) = vbCtrlMask And KeyCode = vbKeyA Then
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End If
    End Sub
    Hack, why must form's KeyPreview be set to True? This is a textbox keydown event, not the form's.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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