Default Edit Menu Options - Undo, Redo Cut, Copy, Paste etc.

I am writing an application and I want to use the standard edit menu with the standard edit functions (cut, copy paste etc.).  Is there a simple way to set up this menu to work the same as the context menu when right clicking on a text box.

Thanks.
marcus_dAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

r_a_j_e_s_hCommented:
no u have to write a code for that.. u have to use clipboard for storing the strings....
0
marcus_dAuthor Commented:
Do you know of any examples to get me started?
0
RonaldBiemansCommented:
Private Sub Menu_Copy(sender As System.Object, e As System.EventArgs)
    ' Ensure that text is selected in the text box.  
    If textBox1.SelectionLength > 0 Then
        ' Copy the selected text to the Clipboard.
        textBox1.Copy()
    End If
End Sub
 
Private Sub Menu_Cut(sender As System.Object, e As System.EventArgs)
    ' Ensure that text is currently selected in the text box.  
    If textBox1.SelectedText <> "" Then
        ' Cut the selected text in the control and paste it into the Clipboard.
        textBox1.Cut()
    End If
End Sub
 
Private Sub Menu_Paste(sender As System.Object, e As System.EventArgs)
    ' Determine if there is any text in the Clipboard to paste into the text box.
    If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = True Then
        ' Determine if any text is selected in the text box.
        If textBox1.SelectionLength > 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", MessageBoxButtons.YesNo) = DialogResult.No Then
                ' Move selection to the point after the current selection and paste.
                textBox1.SelectionStart = textBox1.SelectionStart + _
                    textBox1.SelectionLength
            End If
        End If
        ' Paste current text in Clipboard into text box.
        textBox1.Paste()
    End If
End Sub

Private Sub Menu_Undo(sender As System.Object, e As System.EventArgs)
    ' Determine if last operation can be undone in text box.  
    If textBox1.CanUndo = True Then
        ' Undo the last operation.
        textBox1.Undo()
        ' Clear the undo buffer to prevent last action from being redone.
        textBox1.ClearUndo()
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

marcus_dAuthor Commented:
Thank you, because my forms are made up of a number of different textboxes, do I have to write individual code for each Textbox?
0
RonaldBiemansCommented:
no, you can get textbox in which the menuitem was pressed like, now it will work for every textbox this contextmeun was attachted to

Private Sub Menu_Copy(sender As System.Object, e As System.EventArgs) handles mnuItem1.click
        ' Ensure that text is selected in the text box.  
        If CType(CType(sender, MenuItem).GetContextMenu.SourceControl, TextBox).SelectionLength > 0 Then
            ' Copy the selected text to the Clipboard.
            CType(CType(sender, MenuItem).GetContextMenu.SourceControl, TextBox).Copy()
        End If
    End Sub
0
marcus_dAuthor Commented:
Thank you, that is exactly what I was looking for allbeit that my textboxes are on a child window.  I just replaced the code above with :-

Private Sub m_mCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_mCopy.Click
        ' Ensure that text is selected in the text box.
        If CType(ActiveMdiChild.ActiveControl, TextBox).SelectionLength > 0 Then
            'Copy the selected text to the Clipboard
            CType(ActiveMdiChild.ActiveControl, TextBox).Copy()
        End If
    End Sub

One final question.  How do I enable/disable the menu options? eg. disable paste option when the clipboard is empty, disable the cut & copy options when no text is selected.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.