






|
VB Mania |

|
Previous Example |
|
Cut, Copy and Paste |
|
Information: In this example, you can use the class clipboard to copy, cut and paste text. |
|
Private Sub cmdCopy_Click() ' Copy Clipboard.SetText Text1.SelText End Sub
Private Sub cmdCut_Click() 'Cut Clipboard.SetText Text1.SelText Text1.SelText = "" End Sub
Private Sub cmdPaste_Click() 'Paste Text2.Text = Clipboard.GetText() End Sub |
|
Illustration:
|
|
What You Need?: 1. One form: named form1 2. Two TextBoxes: named text1 and text2 3. Three CommandButtons: named cmdCopy, cmdCut and cmdPaste.
|
|
Code:
|
|
Explanation: CommandButton cmdCopy: it copies the selected text in Text1 in the system clipboard where it can be used later. CommandButton cmdCut: it 'cuts' the selected text in Text1. As you see, it first copies the selected text and then clears from Text1. CommandButton cmdPaste: it pastes the previously copied/cut text into Text2 |
|
Hint: Copy, Cut and Paste are usually implemented in Textboxes; in the run-time if you right-click on any TextBox, a menu will pop-up that will allow you to cut, copy or paste strings. This example shows you the infra-structure of the process. |
|
VB-Pedia: · Clipboard: a member of VB Library that provides access to the system memory. Members used: ¨ Function GetText([Format]) As String: It returns a text string from the Clipboard object ¨ Sub SetText(Str As String, [Format]): It puts a text string on the Clipboard object using the specified Clipboard object format.
· TextBox: a member of VB Library that displays information entered at design time by the user or in code at run time. Properties used: ¨ Property SelText As String It returns/sets the string containing the currently selected text. ¨ Property Text As String It returns/sets the text contained in the control. |


|
Previous Example |
|
Sponsored Links |