Connecting Tech Pros Worldwide Forums | Help | Site Map

Clipboard to Textbox

Raymondo
Guest
 
Posts: n/a
#1: Jun 27 '08
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
Guest
 
Posts: n/a
#2: Jun 27 '08

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
Guest
 
Posts: n/a
#3: Jun 27 '08

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
raymond@raymondos.com

"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
>
>

Closed Thread


Similar Visual Basic 4 / 5 / 6 bytes