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.

[Visual Basic]
Public Sub Copy()

Remarks

You can use this method, instead of using the Clipboard class, to copy text in the text box and place it in the Clipboard.

Example

[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]
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 »

Page Navigation

IndiBlogger Rank

Hit Stats

About Me

My photo
Technology Lover & an IT Professional.

Twitter

http://www.twitterbuttons.com

MeraWindows

Delhi IT Pro

Delhi Devs

IndiBlogger

IE8

IP Address

Friends

AskVG.com
winspark unlockWindows.com techsurface.com

Copyright © 2009-2010 CyberDimensions | Theme Designed by TheBuckmaker | Re-Designed by: Vasu Jain | Home Page Image : Microsoft Windows 7 . | Theme Distributed by Mumbai Mania