Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Disable copy paste in textbox

Disable copy paste in textbox

Scheduled Pinned Locked Moved C#
tutorial
11 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    D i x y
    wrote on last edited by
    #1

    Hello, how to disbale copy paste from and to textbox programatically

    H C 2 Replies Last reply
    0
    • D D i x y

      Hello, how to disbale copy paste from and to textbox programatically

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      hey you might be able to "catch" the event of(ctrl + c) and (ctrl + v) and not handle it... that might do the trick Hav fun

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

      you.suck = (you.passion != Programming)
      
      1 Reply Last reply
      0
      • D D i x y

        Hello, how to disbale copy paste from and to textbox programatically

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You may be able to do this by catching the keystrokes and rejecting them. I don't think there's a paste event. You would probably need to reset the clipboard after a CTRL-Insert or CTRL-C, b/c it's probably already done.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        D 1 Reply Last reply
        0
        • C Christian Graus

          You may be able to do this by catching the keystrokes and rejecting them. I don't think there's a paste event. You would probably need to reset the clipboard after a CTRL-Insert or CTRL-C, b/c it's probably already done.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Like this: private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.Control && e.KeyCode == Keys.C) { e.SuppressKeyPress = true; } else if(e.Control && e.KeyCode == Keys.V) { e.SuppressKeyPress = true; } }

          Avoid Google. Use Blackle[^]

          B 1 Reply Last reply
          0
          • D dan sh

            Like this: private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.Control && e.KeyCode == Keys.C) { e.SuppressKeyPress = true; } else if(e.Control && e.KeyCode == Keys.V) { e.SuppressKeyPress = true; } }

            Avoid Google. Use Blackle[^]

            B Offline
            B Offline
            Bhim Prakash Singh
            wrote on last edited by
            #5

            private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.Control && e.KeyCode == Keys.C) { e.SuppressKeyPress = true; } else if(e.Control && e.KeyCode == Keys.V) { e.SuppressKeyPress = true; } } this is good, but i do't want to this code paste in all control. i want this code type only one time

            D P G 3 Replies Last reply
            0
            • B Bhim Prakash Singh

              private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.Control && e.KeyCode == Keys.C) { e.SuppressKeyPress = true; } else if(e.Control && e.KeyCode == Keys.V) { e.SuppressKeyPress = true; } } this is good, but i do't want to this code paste in all control. i want this code type only one time

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              prakash_adysoft wrote:

              i do't want to this code paste in all control. i want this code type only one time

              Do you mean you want this code to execute only once? If yes then just unbind it using this.textBox1.KeyDown -= new KeyEventHandler(this.textBox1_KeyDown);

              Avoid Google. Use Blackle[^]

              1 Reply Last reply
              0
              • B Bhim Prakash Singh

                private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.Control && e.KeyCode == Keys.C) { e.SuppressKeyPress = true; } else if(e.Control && e.KeyCode == Keys.V) { e.SuppressKeyPress = true; } } this is good, but i do't want to this code paste in all control. i want this code type only one time

                P Offline
                P Offline
                phannon86
                wrote on last edited by
                #7

                Aside from the fact he probably shouldn't have just posted up this code as an instant solution (requiring the OP to do nothing for himself), the code only needs to be written once, you can bind one event to multiple controls.

                He who makes a beast out of himself gets rid of the pain of being a man

                1 Reply Last reply
                0
                • B Bhim Prakash Singh

                  private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.Control && e.KeyCode == Keys.C) { e.SuppressKeyPress = true; } else if(e.Control && e.KeyCode == Keys.V) { e.SuppressKeyPress = true; } } this is good, but i do't want to this code paste in all control. i want this code type only one time

                  G Offline
                  G Offline
                  Giorgi Dalakishvili
                  wrote on last edited by
                  #8

                  What if the user copies or pasties using context menu of the textbox?

                  Giorgi Dalakishvili #region signature my articles #endregion

                  D 1 Reply Last reply
                  0
                  • G Giorgi Dalakishvili

                    What if the user copies or pasties using context menu of the textbox?

                    Giorgi Dalakishvili #region signature my articles #endregion

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #9

                    Just reinitialize the context menu of the textbox during form load without any items in it.

                    Avoid Google. Use Blackle[^]

                    A 1 Reply Last reply
                    0
                    • D dan sh

                      Just reinitialize the context menu of the textbox during form load without any items in it.

                      Avoid Google. Use Blackle[^]

                      A Offline
                      A Offline
                      Anthony Mushrow
                      wrote on last edited by
                      #10

                      I actually found a bug, where you can still get the context menu even when you do that. If i remember right, to get the context menu to STILL appear, you right-click the text box and hold the button down - move you mouse off of the text box - and then release the button. Then the normal menu appears :confused:

                      My current favourite word is: Bacon!

                      -SK Genius

                      Game Programming articles start -here[^]-

                      D 1 Reply Last reply
                      0
                      • A Anthony Mushrow

                        I actually found a bug, where you can still get the context menu even when you do that. If i remember right, to get the context menu to STILL appear, you right-click the text box and hold the button down - move you mouse off of the text box - and then release the button. Then the normal menu appears :confused:

                        My current favourite word is: Bacon!

                        -SK Genius

                        Game Programming articles start -here[^]-

                        D Offline
                        D Offline
                        dan sh
                        wrote on last edited by
                        #11

                        Thanks for find. How about handling this in WndProc method then?

                        Avoid Google. Use Blackle[^]

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups