如何复制文本框的内容?
如:在一个TEXT1.TEXT有一个字符串,如何通过单击一个按钮把它复制(能用CTRL+V实现粘贴)?
[解决办法]
上面的代码有些问题, 复制的内容不能粘贴到其他应用程序中,换下面的代码试试:
Option Explicit
Private Declare Function CloseClipboard Lib "user32 " () As Long
Private Declare Function OpenClipboard Lib "user32 " (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32 " () As Long
Private Declare Function SetClipboardData Lib "user32 " (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32 " (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Long)
Const GMEM_FIXED = 0
Private Sub Command1_Click()
Dim hText As Long
Dim bText() As Byte
Dim iLength As Long
bText = StrConv(Text1.Text, vbFromUnicode)
iLength = UBound(bText) + 1
hText = GlobalAlloc(GMEM_FIXED, iLength + 1)
CopyMemory hText, VarPtr(bText(0)), iLength
OpenClipboard Me.hwnd
EmptyClipboard
SetClipboardData vbCFText, hText
CloseClipboard
End Sub