Cut, Copy, Paste code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Cut, Copy, Paste code

    Hi

    In a winform app I need to provide a menu with Cut, Copy and Paste options.,
    What code do I use to accomplish cut, copy and paste features for fields on
    a winfrom?

    Thanks

    Regards


  • Cor Ligthert[MVP]

    #2
    Re: Cut, Copy, Paste code

    John,

    You are probably at the moment the guy who asks the most in these
    newsgroups, no problem, however by just copying in your problem in MSDN you
    get all the answers you want about that.

    When you set your search string than use the trick to set as
    well -blogs -forums to prevent that you get all kind of rubish.

    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    When you can not get your answer there, or it is not clear to you, then
    place your question here.

    Cor

    "John" <info@nospam.in fovis.co.ukschr eef in bericht
    news:OqxBuEjiIH A.4684@TK2MSFTN GP06.phx.gbl...
    Hi
    >
    In a winform app I need to provide a menu with Cut, Copy and Paste
    options., What code do I use to accomplish cut, copy and paste features
    for fields on a winfrom?
    >
    Thanks
    >
    Regards
    >

    Comment

    • RobinS

      #3
      Re: Cut, Copy, Paste code

      What are you trying to cut, copy, and paste? The data displayed on the whole
      form? Text in a textbox?

      RobinS.
      GoldMail.com

      "John" <info@nospam.in fovis.co.ukwrot e in message
      news:OqxBuEjiIH A.4684@TK2MSFTN GP06.phx.gbl...
      Hi
      >
      In a winform app I need to provide a menu with Cut, Copy and Paste
      options., What code do I use to accomplish cut, copy and paste features
      for fields on a winfrom?
      >
      Thanks
      >
      Regards
      >

      Comment

      • kimiraikkonen

        #4
        Re: Cut, Copy, Paste code

        On Mar 20, 4:22 am, "John" <i...@nospam.in fovis.co.ukwrot e:
        Hi
        >
        In a winform app I need to provide a menu with Cut, Copy and Paste options.,
        What code do I use to accomplish cut, copy and paste features for fields on
        a winfrom?
        >
        Thanks
        >
        Regards
        John,
        For your purpose, there's a built-in template does this. Insert
        MenuStrip control. Right click -Insert Standard Items.

        Now the items that you're looking for are created, now just you need
        to write codes for each item.

        Comment

        • John

          #5
          Re: Cut, Copy, Paste code

          Text in fields.

          Thanks

          Regards

          "RobinS" <robins@imnotte lling.comwrote in message
          news:hICdnRDEi8-LmX_anZ2dnUVZ_u WlnZ2d@comcast. com...
          What are you trying to cut, copy, and paste? The data displayed on the
          whole form? Text in a textbox?
          >
          RobinS.
          GoldMail.com
          >
          "John" <info@nospam.in fovis.co.ukwrot e in message
          news:OqxBuEjiIH A.4684@TK2MSFTN GP06.phx.gbl...
          >Hi
          >>
          >In a winform app I need to provide a menu with Cut, Copy and Paste
          >options., What code do I use to accomplish cut, copy and paste features
          >for fields on a winfrom?
          >>
          >Thanks
          >>
          >Regards
          >>
          >

          Comment

          • John

            #6
            Re: Cut, Copy, Paste code

            I only need code for actual Copy, Cut and paste operation. I already have
            menus (infragistics) setup.

            Thanks

            Regards

            "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
            news:e5f739ef-cacf-434a-951e-d40b851746bf@a2 3g2000hsc.googl egroups.com...
            On Mar 20, 4:22 am, "John" <i...@nospam.in fovis.co.ukwrot e:
            >Hi
            >>
            >In a winform app I need to provide a menu with Cut, Copy and Paste
            >options.,
            >What code do I use to accomplish cut, copy and paste features for fields
            >on
            >a winfrom?
            >>
            >Thanks
            >>
            >Regards
            >
            John,
            For your purpose, there's a built-in template does this. Insert
            MenuStrip control. Right click -Insert Standard Items.
            >
            Now the items that you're looking for are created, now just you need
            to write codes for each item.

            Comment

            • kevininstructor@state.or.us

              #7
              Re: Cut, Copy, Paste code

              Add a context menu to the text control
              Add menu items i.e. copy/cut/paste.
              Add commands to the menu items

              Delete
              My.Computer.Cli pboard.SetText( TextBox1.Select edText)
              TextBox1.Text = TextBox1.Text.R eplace(TextBox1 .SelectedText, "")

              SelectAll
              TextBox1.Select All()

              Paste
              TextBox1.Text = My.Computer.Cli pboard.GetText

              Undo
              TextBox1.Undo()

              Cut
              My.Computer.Cli pboard.SetText( TextBox1.Text)
              TextBox1.Text = ""

              Also make sure to enable/disable menu items kind like the following
              Private Sub TextBox1_TextCh anged(ByVal sender As System.Object,
              ByVal e As System.EventArg s)
              Handles TextBox1.TextCh anged

              PasteToolStripM enuItem.Enabled = My.Computer.Cli pboard.Contains Text
              DeleteToolStrip MenuItem.Enable d = TextBox1.Select ionLength 0
              CutToolStripMen uItem.Enabled = DeleteToolStrip MenuItem.Enable d
              CopyToolStripMe nuItem.Enabled = DeleteToolStrip MenuItem.Enable d
              UndoToolStripMe nuItem.Enabled = TextBox1.CanUnd o
              End Sub

              Your context menu will replace the normal menu say on a textbox.

              Hope this helps,
              Kevin

              "John" <info@nospam.in fovis.co.ukwrot e in message
              news:OqxBuEjiIH A.4684@TK2MSFTN GP06.phx.gbl...
              Hi
              >
              In a winform app I need to provide a menu with Cut, Copy and Paste
              options., What code do I use to accomplish cut, copy and paste features
              for fields on a winfrom?
              >
              Thanks
              >
              Regards
              >

              Comment

              • John

                #8
                Re: Cut, Copy, Paste code

                Hi Kevin

                Many thanks. This is very useful.

                Regards

                "kevininstructo r@state.or.us" <Kevin.S.Gallag her@state.or.us wrote in
                message news:%23PdGAroi IHA.1132@TK2MSF TNGP06.phx.gbl. ..
                Add a context menu to the text control
                Add menu items i.e. copy/cut/paste.
                Add commands to the menu items
                >
                Delete
                My.Computer.Cli pboard.SetText( TextBox1.Select edText)
                TextBox1.Text = TextBox1.Text.R eplace(TextBox1 .SelectedText, "")
                >
                SelectAll
                TextBox1.Select All()
                >
                Paste
                TextBox1.Text = My.Computer.Cli pboard.GetText
                >
                Undo
                TextBox1.Undo()
                >
                Cut
                My.Computer.Cli pboard.SetText( TextBox1.Text)
                TextBox1.Text = ""
                >
                Also make sure to enable/disable menu items kind like the following
                Private Sub TextBox1_TextCh anged(ByVal sender As System.Object,
                ByVal e As System.EventArg s)
                Handles TextBox1.TextCh anged
                >
                PasteToolStripM enuItem.Enabled = My.Computer.Cli pboard.Contains Text
                DeleteToolStrip MenuItem.Enable d = TextBox1.Select ionLength 0
                CutToolStripMen uItem.Enabled = DeleteToolStrip MenuItem.Enable d
                CopyToolStripMe nuItem.Enabled = DeleteToolStrip MenuItem.Enable d
                UndoToolStripMe nuItem.Enabled = TextBox1.CanUnd o
                End Sub
                >
                Your context menu will replace the normal menu say on a textbox.
                >
                Hope this helps,
                Kevin
                >
                "John" <info@nospam.in fovis.co.ukwrot e in message
                news:OqxBuEjiIH A.4684@TK2MSFTN GP06.phx.gbl...
                >Hi
                >>
                >In a winform app I need to provide a menu with Cut, Copy and Paste
                >options., What code do I use to accomplish cut, copy and paste features
                >for fields on a winfrom?
                >>
                >Thanks
                >>
                >Regards
                >>
                >
                >

                Comment

                • Armin Zingler

                  #9
                  Re: Cut, Copy, Paste code

                  "John" <info@nospam.in fovis.co.ukschr ieb
                  Hi
                  >
                  In a winform app I need to provide a menu with Cut, Copy and Paste
                  options., What code do I use to accomplish cut, copy and paste
                  features for fields on a winfrom?
                  I wonder why you want to do something that you don't know how to do it.
                  I want to build an aircraft, but I don't know how to do, so I don't do
                  it. If I work in an aircraft building company and am instructed to build
                  an aircraft and don't know how to do it, I'd wonder if it is the right
                  job for me. You seem to work in such a company and ask the fellow
                  workers to do the work for you because you don't know how to do it - so,
                  what do you get paid for?


                  Armin

                  Comment

                  • Steve Gerrard

                    #10
                    Re: Cut, Copy, Paste code

                    John wrote:
                    Hi Kevin
                    >
                    Many thanks. This is very useful.
                    >
                    Regards
                    >
                    Before you go implementing all of that, have you right clicked on a text box
                    before? There is already a context menu with all of that in there. Just
                    wondering why you are replacing a working wheel...


                    Comment

                    • John

                      #11
                      Re: Cut, Copy, Paste code

                      Steve this is fine but I need to implement these in the main menu on the
                      top.

                      Thanks

                      Regards

                      "Steve Gerrard" <mynamehere@com cast.netwrote in message
                      news:Vq6dnQrxbv nE6H_anZ2dnUVZ_ gadnZ2d@comcast .com...
                      John wrote:
                      >Hi Kevin
                      >>
                      >Many thanks. This is very useful.
                      >>
                      >Regards
                      >>
                      >
                      Before you go implementing all of that, have you right clicked on a text
                      box before? There is already a context menu with all of that in there.
                      Just wondering why you are replacing a working wheel...
                      >
                      >

                      Comment

                      • N Morrison

                        #12
                        Re: Cut, Copy, Paste code

                        On Mar 20, 2:07 am, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
                        John,
                        For your purpose, there's a built-in template does this. Insert
                        MenuStrip control. Right click -Insert Standard Items.
                        >
                        Now the items that you're looking for are created, now just you need
                        to write codes for each item.
                        Which doesn't help him (or me) that much. This is what I came up with
                        (most leeched from the MSDN example but hacked to work on any textbox
                        for example. For other controls add code as needed):

                        Private Function GetControl() As Control
                        Dim cControl As ContainerContro l, aControl As Control

                        aControl = Me.ActiveContro l

                        Do
                        If TypeOf aControl Is TextBox Then Exit Do
                        ' Cast to ContainerContro l to access next level
                        ActiveControl
                        cControl = CType(aControl, ContainerContro l)
                        aControl = cControl.Active Control
                        Loop

                        If TypeOf aControl Is TextBox Then
                        GetControl = aControl
                        Else
                        GetControl = Nothing
                        End If

                        End Function

                        Private Sub Menu_Copy(ByVal sender As System.Object, ByVal e As
                        System.EventArg s) Handles mnuCopy.Click, btnCopy.Click
                        Dim tControl As TextBox
                        ' Ensure that text is selected in the text box.
                        tControl = CType(GetContro l(), TextBox)
                        If tControl.Select ionLength 0 Then
                        ' Copy the selected text to the Clipboard.
                        tControl.Copy()
                        End If
                        End Sub

                        Private Sub Menu_Cut(ByVal sender As System.Object, ByVal e As
                        System.EventArg s) Handles mnuCut.Click, btnCut.Click
                        Dim tControl As TextBox
                        ' Ensure that text is currently selected in the text box.
                        tControl = CType(GetContro l(), TextBox)
                        If tControl.Select edText <"" Then
                        ' Cut the selected text in the control and paste it into
                        the Clipboard.
                        tControl.Cut()
                        End If
                        End Sub

                        Private Sub Menu_Paste(ByVa l sender As System.Object, ByVal e As
                        System.EventArg s) Handles mnuPaste.Click, btnPaste.Click
                        Dim tControl As TextBox
                        ' Determine if there is any text in the Clipboard to paste
                        into the text box.
                        tControl = CType(GetContro l(), TextBox)
                        If Clipboard.GetDa taObject().GetD ataPresent(Data Formats.Text)
                        = True Then
                        ' Determine if any text is selected in the text box.
                        If tControl.Select ionLength 0 Then
                        ' Ask user if they want to paste over currently
                        selected text.
                        If MessageBox.Show ("Do you want to paste over current
                        selection?", _
                        "Cut Example", MessageBoxButto ns.YesNo) =
                        DialogResult.No Then
                        ' Move selection to the point after the current
                        selection and paste.
                        tControl.Select ionStart = tControl.Select ionStart
                        + _
                        tControl.Select ionLength
                        End If
                        End If
                        ' Paste current text in Clipboard into text box.
                        tControl.Paste( )
                        End If
                        End Sub

                        Private Sub Menu_Undo(ByVal sender As System.Object, ByVal e As
                        System.EventArg s) Handles mnuUndo.Click
                        Dim tControl As TextBox
                        tControl = CType(GetContro l(), TextBox)
                        ' Determine if last operation can be undone in text box.
                        If tControl.CanUnd o = True Then
                        ' Undo the last operation.
                        tControl.Undo()
                        ' Clear the undo buffer to prevent last action from being
                        redone.
                        tControl.ClearU ndo()
                        End If
                        End Sub

                        Comment

                        Working...