Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 22, 1997

Sharing Text Between Applications

Question:
How can I get text selected in an application, say notepad into a vb text box in my application. Then, what about the reverse: if i have text in a text box (i want to use all of it (i.e. not selected) how can I get it to paste into another apps edit box at the current position of the cursor?

Answer:
Cut, copy and paste code is very easy to do. I always provide an Edit menu in my applications and make this code available within the choices. You are basically using the Clipboard object to transfer data to and from other applications or within your own application. Each of these menu items (which are named so that you can figure out what they do) first check the current control to make sure that it is a TextBox control. They then use the appropriate method of the Clipboard to cut, copy, or paste text to or from the control. You can remove the If/Then statement if you wish. ActiveForm is a property of the MDI form which points to the currently active child form within the MDI frame. ActiveControl is the currently active control on that form. You can replace ActiveForm.ActiveControl with the name of your text box, if you wish.

Private Sub mnEditCopy_Click()
   If TypeOf ActiveForm.ActiveControl Is TextBox Then
      Clipboard.SetText ActiveForm.ActiveControl.SelText
   End If
End Sub

Private Sub mnEditCut_Click()
   If TypeOf ActiveForm.ActiveControl Is TextBox Then
      Clipboard.SetText ActiveForm.ActiveControl.SelText
      ActiveForm.ActiveControl.SelText = ""
   End If
End Sub

Private Sub mnEditPaste_Click()
   If TypeOf ActiveForm.ActiveControl Is TextBox Then
      ActiveForm.ActiveControl.SelText = Clipboard.GetText
   End If
End Sub

Private Sub mnEditSelectAll_Click()
   If TypeOf ActiveForm.ActiveControl Is TextBox Then
      Me.ActiveForm.ActiveControl.SelStart = 1
      Me.ActiveForm.ActiveControl.SelLength =
Len(ActiveForm.ActiveControl.Text)
   End If
End Sub
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date