Connecting Tech Pros Worldwide Help | Site Map

Clipboard to Textbox

  #1  
Old June 27th, 2008, 05:16 PM
Raymondo
Guest
 
Posts: 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


  #2  
Old June 27th, 2008, 05:16 PM
Raoul Watson
Guest
 
Posts: n/a

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


  #3  
Old June 27th, 2008, 05:16 PM
Raymondo
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
Win API can't retrieve palette from clipboard active answers 8 July 16th, 2007 02:05 PM
reading clipboard Jaez answers 3 May 10th, 2007 08:45 PM
Appending Input to TextBox Richard Grene answers 2 November 20th, 2005 06:08 PM
Paste from clipboard in asp.net fs answers 1 November 19th, 2005 05:48 AM