Edit menu

  • Thread starter Thread starter Gilbert Tordeur
  • Start date Start date
G

Gilbert Tordeur

I suppose a lot of people have already written an Edit menu (Cut, Copy,
Select all, C/Z, C/Y...) for a text box and other adequate controls. Where
can I find the necessary statements in VB.Net ? Thank you.
 
Hi Gilbert,

A simple text box Cut, Copy, Paste and Select All in VB.Net would be
something like;

Private Sub mnuCut_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuCut.Click

Clipboard.SetDataObject(TextBox1.SelectedText, True)
TextBox1.SelectedText = ""

End Sub

Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuCopy.Click
Clipboard.SetDataObject(TextBox1.SelectedText, True)

End Sub

Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPaste.Click

Dim ClipboardData As IDataObject = Clipboard.GetDataObject()
If ClipboardData.GetDataPresent(DataFormats.Text) Then
TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart,
CType(ClipboardData.GetData(DataFormats.Text), String))
End If

End Sub

Private Sub mnuSelectAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSelectAll.Click

With TextBox1
.SelectionStart = 0
.SelectionLength = .TextLength
End With

End Sub

Regards,

Gerard O'Donnell (MCSD)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top