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. clipboard pastes two times

clipboard pastes two times

Scheduled Pinned Locked Moved C#
comhelpquestion
10 Posts 5 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.
  • E Offline
    E Offline
    Erdinc27
    wrote on last edited by
    #1

    i want to copy a tex from texbox and paste it another one in my form i copy it with that code

    Clipboard.SetText(textBox1.SelectedText);

    and paste it with that

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
    if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
    textBox2.Text = Clipboard.GetText();
    }

    but the problem is it pastes selceted text two times but when i try like that

    (e.Modifiers == Keys.Control)

    it pastes one time what should i do now ?

    vemedya.com

    J realJSOPR 2 Replies Last reply
    0
    • E Erdinc27

      i want to copy a tex from texbox and paste it another one in my form i copy it with that code

      Clipboard.SetText(textBox1.SelectedText);

      and paste it with that

      private void Form1_KeyDown(object sender, KeyEventArgs e)
      {
      if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
      textBox2.Text = Clipboard.GetText();
      }

      but the problem is it pastes selceted text two times but when i try like that

      (e.Modifiers == Keys.Control)

      it pastes one time what should i do now ?

      vemedya.com

      J Offline
      J Offline
      JF2015
      wrote on last edited by
      #2

      I've tested your code and it is working fine for me. I think that the problem must be somewhere else. What is the content of the Clipboard when pasting?

      E 1 Reply Last reply
      0
      • J JF2015

        I've tested your code and it is working fine for me. I think that the problem must be somewhere else. What is the content of the Clipboard when pasting?

        E Offline
        E Offline
        Erdinc27
        wrote on last edited by
        #3

        its content is te selected text from the textbox..for example if i write 'w' in my textbox and paste it to my another box it appears 'ww'

        vemedya.com

        E 1 Reply Last reply
        0
        • E Erdinc27

          its content is te selected text from the textbox..for example if i write 'w' in my textbox and paste it to my another box it appears 'ww'

          vemedya.com

          E Offline
          E Offline
          Erdinc27
          wrote on last edited by
          #4

          hey friend thanks for reply..i solved my problem ..i set my form's KeyPreview false and it works now..

          vemedya.com

          J L 2 Replies Last reply
          0
          • E Erdinc27

            hey friend thanks for reply..i solved my problem ..i set my form's KeyPreview false and it works now..

            vemedya.com

            J Offline
            J Offline
            JF2015
            wrote on last edited by
            #5

            Glad to help - at least your code is correct. All I could do is tell you that the problem must be somewhere else :-D

            1 Reply Last reply
            0
            • E Erdinc27

              hey friend thanks for reply..i solved my problem ..i set my form's KeyPreview false and it works now..

              vemedya.com

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              CTRL/V is handled automatically by some Controls. You make the Form react to it, but didn't tell the system that is all you want to happen, so if a suitable Control has focus, it will still oblige the CTRL/V. Clearing KeyPreview is unlikely the solution; it was set for a reason. Look for KeyEventArgs.Handled and SuppressKeyPress. :)

              Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

              Season's Greetings to all CPians.

              1 Reply Last reply
              0
              • E Erdinc27

                i want to copy a tex from texbox and paste it another one in my form i copy it with that code

                Clipboard.SetText(textBox1.SelectedText);

                and paste it with that

                private void Form1_KeyDown(object sender, KeyEventArgs e)
                {
                if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
                textBox2.Text = Clipboard.GetText();
                }

                but the problem is it pastes selceted text two times but when i try like that

                (e.Modifiers == Keys.Control)

                it pastes one time what should i do now ?

                vemedya.com

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #7

                I believe you want to handle an event for the control you're pasting into as opposed to handling it in the form.

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                E 1 Reply Last reply
                0
                • realJSOPR realJSOP

                  I believe you want to handle an event for the control you're pasting into as opposed to handling it in the form.

                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                  -----
                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                  E Offline
                  E Offline
                  Erdinc27
                  wrote on last edited by
                  #8

                  i have 17 textboxes on my form and i want the user can copy from one box and paste to another...that is why i did so

                  private void Form1_KeyDown(object sender, KeyEventArgs e)
                  {
                  if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.V))
                  {
                  foreach (Control item in this.Controls)
                  {
                  if (item.GetType().Name == "TextBox")
                  if (item.Enabled)
                  item.Text = Clipboard.GetText();
                  }
                  }
                  }

                  it works well..but after i saw your replies i wonder if there is better way or i am in wrong way ?

                  vemedya.com

                  realJSOPR D 2 Replies Last reply
                  0
                  • E Erdinc27

                    i have 17 textboxes on my form and i want the user can copy from one box and paste to another...that is why i did so

                    private void Form1_KeyDown(object sender, KeyEventArgs e)
                    {
                    if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.V))
                    {
                    foreach (Control item in this.Controls)
                    {
                    if (item.GetType().Name == "TextBox")
                    if (item.Enabled)
                    item.Text = Clipboard.GetText();
                    }
                    }
                    }

                    it works well..but after i saw your replies i wonder if there is better way or i am in wrong way ?

                    vemedya.com

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #9

                    I found this on google (search phrase is "c# textbox events"): http://www.vcskicks.com/clipboard-textbox.php[^]

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                    1 Reply Last reply
                    0
                    • E Erdinc27

                      i have 17 textboxes on my form and i want the user can copy from one box and paste to another...that is why i did so

                      private void Form1_KeyDown(object sender, KeyEventArgs e)
                      {
                      if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.V))
                      {
                      foreach (Control item in this.Controls)
                      {
                      if (item.GetType().Name == "TextBox")
                      if (item.Enabled)
                      item.Text = Clipboard.GetText();
                      }
                      }
                      }

                      it works well..but after i saw your replies i wonder if there is better way or i am in wrong way ?

                      vemedya.com

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      You shoulnd't have to do anything at all. The TextBox already supports Copy/Paste on its own without any code from you.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak

                      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