Results 1 to 5 of 5

Thread: Copy Paste Shortcut key

  1. #1

    Thread Starter
    Banned
    Join Date
    Mar 2018
    Location
    GB
    Posts
    12

    Question Copy Paste Shortcut key

    How do i add a copy , paste , cut, delete shortcut key to my appliaction

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Copy Paste Shortcut key

    It depends. If you are using a ToolStripMenuItems for the commands, then you'd assign the ShortcutKeys property equal to the various combinations either in the designer or via code:
    Code:
    CopyToolStripMenuItem.ShortcutKeys = Keys.Control Or Keys.C
    Otherwise, if you just want a global command to reside on the Form, then generate the KeyDown event and check for the various combinations:
    Code:
    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        If e.Control AndAlso e.KeyCode = Keys.C Then
    
        ElseIf e.Control AndAlso e.KeyCode = Keys.X Then
    
        'ElseIf etc.. Then...
    
        End If
    End Sub
    Just be mindful that in this case you'd probably want to set the Form's KeyPreview property to True.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Copy Paste Shortcut key

    Actually, you may not need this. Windows already has such functionality that will work with textboxes, and I seem to remember that's what you were using. Ctrl+C is copy, Ctrl+V is paste, Ctrl+X is cut. Are you needing more than that?
    My usual boring signature: Nothing

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Copy Paste Shortcut key

    Quote Originally Posted by Shaggy Hiker View Post
    Actually, you may not need this. Windows already has such functionality that will work with textboxes, and I seem to remember that's what you were using. Ctrl+C is copy, Ctrl+V is paste, Ctrl+X is cut. Are you needing more than that?
    I recently inherited an application to support and the previous programmer set up an "Edit" menu for cut, copy, paste. I'd post a picture but one of the first things I did was remove it and let standard Windows key combinations work. I got a lot of thanks for that...I had asked the users first before gutting it and not one person preferred the menu over keys. I say; let Windows work the way Windows works. That way all your apps are relatively consistent.

    It used ToolStripMenuItems as mentioned in post #2.
    Please remember next time...elections matter!

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

    Re: Copy Paste Shortcut key

    Quote Originally Posted by TysonLPrice View Post
    I recently inherited an application to support and the previous programmer set up an "Edit" menu for cut, copy, paste. I'd post a picture but one of the first things I did was remove it and let standard Windows key combinations work. I got a lot of thanks for that...I had asked the users first before gutting it and not one person preferred the menu over keys. I say; let Windows work the way Windows works. That way all your apps are relatively consistent.

    It used ToolStripMenuItems as mentioned in post #2.
    Not just that but, unless you have set the ContextMenuStrip property of a TextBox explicitly, right-clicking a TextBox will display the default context menu and that contains Cut, Copy and Paste items. The same goes for a ComboBox with its DropDownStyle set to DropDown, although not for a RichTextBox.

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