Copying the selected text in a textbox to clipboard
Often in programming we ned to copy the selected text to the clipoard. Here is the method how to do this in visualbasic.net Copies the current selection in the text box to the Clipboard. You can use this method, instead of using the Clipboard class, to copy text in the text box and place it in the Clipboard. [Visual Basic, C#, C++] The following example uses TextBox, a derived class. It provides Click event handlers for MenuItem objects that perform Cut, Copy, Paste, and Undo operations. This example assumes that a TextBox control named textBox1 has been created.[Visual Basic]
Public Sub Copy()Remarks
Example
[Visual Basic]
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
0 Comments »
Post a Comment