Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Clipboard to Textbox

Question posted by: Raymondo (Guest) on June 27th, 2008 04:16 PM
Hi,
I have several textboxes, I want to click on one to select it, then click a
button to insert the text from the clipboard into it.
I've tried several ways to do this, but can't figure it out.
Can anyone help! (simply)
Sorry I'm a eejit.,
Raymondo


Raoul Watson's Avatar
Raoul Watson
Guest
n/a Posts
June 27th, 2008
04:16 PM
#2

Re: Clipboard to Textbox

"Raymondo" <raymond@zyko.co.ukwrote in message
news:T-idne5tPYN6tbLVnZ2dnUVZ8sXinZ2d@bt.com...
Quote:
Hi,
I have several textboxes, I want to click on one to select it, then click
a
button to insert the text from the clipboard into it.
I've tried several ways to do this, but can't figure it out.
Can anyone help! (simply)
Sorry I'm a eejit.,
Raymondo
>


A couple of ways.. The first is simplest:

Clipboard.GetText Text1.Text

If you need more control, you can also use the SendMessage method..

'------------ in a module ---------
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Public Const EM_UNDO = &HC7
Public Const WM_CUT = &H300
Public Const WM_COPY = &H301
Public Const WM_PASTE = &H302

'--------------- in the forms ----------------
'--------- UNDO ----------
gResult = SendMessage(Screen.ActiveControl.hWnd, EM_UNDO, 1, 0)
'--------- COPY ----------
Clipboard.Clear
gResult = SendMessage(Screen.ActiveControl.hWnd, WM_COPY, 1, 0)
'--------- CUT -----------
gResult = SendMessage(Screen.ActiveControl.hWnd, WM_CUT, 1, 0)
'--------- PASTE ---------
gResult = SendMessage(Screen.ActiveControl.hWnd, WM_PASTE, 1, 0)


Just make sure activecontrol can accept the message. You can do a quick test
for example, let's say you have richtext boxes and you want to handle copy
cut and paste strictly on a richtext:

If TypeOf Screen.ActiveControl Is RichTextBox Then...
' accept copy, cut, and paste



Raymondo's Avatar
Raymondo
Guest
n/a Posts
June 27th, 2008
04:16 PM
#3

Re: Clipboard to Textbox
Thanks Raoul, It is just a simple program to print envelopes.
The second solution is way above my head, but the first is spot-on.
I'll work with that.
Many thanks for taking the time to answer my question.
Regards,
Raymondo
Join Bytes!

"Raoul Watson" <WatsonR@IntelligenCIA.comwrote in message
news:_HVXj.1159$pk1.642@trndny07...
Quote:
>
"Raymondo" <raymond@zyko.co.ukwrote in message
news:T-idne5tPYN6tbLVnZ2dnUVZ8sXinZ2d@bt.com...
Quote:
>Hi,
>I have several textboxes, I want to click on one to select it, then click
>a
>button to insert the text from the clipboard into it.
>I've tried several ways to do this, but can't figure it out.
>Can anyone help! (simply)
>Sorry I'm a eejit.,
>Raymondo
>>

>
A couple of ways.. The first is simplest:
>
Clipboard.GetText Text1.Text
>
If you need more control, you can also use the SendMessage method..
>
'------------ in a module ---------
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
>
Public Const EM_UNDO = &HC7
Public Const WM_CUT = &H300
Public Const WM_COPY = &H301
Public Const WM_PASTE = &H302
>
'--------------- in the forms ----------------
'--------- UNDO ----------
gResult = SendMessage(Screen.ActiveControl.hWnd, EM_UNDO, 1, 0)
'--------- COPY ----------
Clipboard.Clear
gResult = SendMessage(Screen.ActiveControl.hWnd, WM_COPY, 1, 0)
'--------- CUT -----------
gResult = SendMessage(Screen.ActiveControl.hWnd, WM_CUT, 1, 0)
'--------- PASTE ---------
gResult = SendMessage(Screen.ActiveControl.hWnd, WM_PASTE, 1, 0)
>
>
Just make sure activecontrol can accept the message. You can do a quick
test for example, let's say you have richtext boxes and you want to handle
copy cut and paste strictly on a richtext:
>
If TypeOf Screen.ActiveControl Is RichTextBox Then...
' accept copy, cut, and paste
>
>




 
Not the answer you were looking for? Post your question . . .
189,873 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors