Results 1 to 7 of 7

Thread: VB6 - RichTextBox: Disabling Cut, Copy & Paste

  1. #1

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    VB6 - RichTextBox: Disabling Cut, Copy & Paste

    Hai friends,
    Here is a solution to the common problem of disabling cut, copy and paste in a RichTextBox Control.
    I had found it after certain experiments...
    I hope, you all will like it..
    Below is the code:
    Code:
    'Created by Akhilesh B Chandran
    
    Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 45 And Shift = 1 Then KeyCode = 0 'paste(shift + insert)
    If KeyCode = 45 And Shift = 2 Then KeyCode = 0 'copy(ctrl + insert)
    If KeyCode = 86 And Shift = 2 Then KeyCode = 0 'paste(ctrl + v)
    If KeyCode = 67 And Shift = 2 Then KeyCode = 0 'copy(ctrl + c)
    If KeyCode = 88 And Shift = 2 Then KeyCode = 0 'cut(ctrl + x)
    End Sub
    Note: You have to set the AutoVerbMenu property of the Richtextbox control to False(for disabling the popup menu on right click)

    Please post your comments and suggestions...

    -Regards
    Akhilesh B Chandran
    Attached Files Attached Files

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: VB6 - RichTextBox: Disabling Cut, Copy & Paste

    I can still copy, cut and paste using the keyboard.
    Just use 3 keys instead of 2, Control+Shift+The_Key

    Not sure is this any better or not? >
    Code:
    Option Explicit
    Private CntrlKey As Boolean
    
    Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
        
        If KeyCode = vbKeyControl Then
            CntrlKey = True
        End If
        
        Select Case KeyCode
            Case vbKeyZ, vbKeyX, vbKeyC, vbKeyV, vbKeyInsert
                If CntrlKey = True Then KeyCode = 0
        End Select
        
        If (Shift And vbShiftMask) And vbKeyInsert Then
            KeyCode = 0
        End If
    
    End Sub
    
    Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer)
       
        If KeyCode = vbKeyControl Then
            CntrlKey = False
        End If
       
    End Sub
    Last edited by Edgemeal; Sep 12th, 2008 at 12:24 PM.

  3. #3

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: VB6 - RichTextBox: Disabling Cut, Copy & Paste

    I didnt know that it was possible with 3 keys. Thanks for the code

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    Lively Member
    Join Date
    May 2008
    Location
    Manila, Philippines
    Posts
    81

    Re: VB6 - RichTextBox: Disabling Cut, Copy & Paste

    another thing to paste
    A
    1) click on the textbox
    2) shift + F10
    3) click paste

    B.
    1) right click on the textbox
    2) click on paste

  5. #5

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: VB6 - RichTextBox: Disabling Cut, Copy & Paste

    Quote Originally Posted by youquijano View Post
    another thing to paste
    A
    1) click on the textbox
    2) shift + F10
    3) click paste

    B.
    1) right click on the textbox
    2) click on paste
    We are discussing about Richtextbox And we have disabled the AutoVerbMenu (see post #1). So, no problem with that

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6
    Lively Member
    Join Date
    May 2008
    Location
    Manila, Philippines
    Posts
    81

    Re: VB6 - RichTextBox: Disabling Cut, Copy & Paste

    my bad. but im asking for textboxes on how to disable them

  7. #7

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: VB6 - RichTextBox: Disabling Cut, Copy & Paste

    Quote Originally Posted by youquijano View Post
    my bad. but im asking for textboxes on how to disable them
    Did you tried searching this forum ? I think, it has been asked for several times.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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