By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Clipboard to Textbox

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Raymondo" <ra*****@zyko.co.ukwrote in message
news:T-******************************@bt.com...
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
Jun 27 '08 #2

P: n/a
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
ra*****@raymondos.com

"Raoul Watson" <Wa*****@IntelligenCIA.comwrote in message
news:_HVXj.1159$pk1.642@trndny07...
>
"Raymondo" <ra*****@zyko.co.ukwrote in message
news:T-******************************@bt.com...
>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


Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.