请问vb怎样编写代码把复制,剪切,粘贴东西到别处

2024-11-16 23:21:51
推荐回答(2个)
回答1:

如果焦点在Text1的话单击粘帖是不是自动粘帖到Text2?
不知道这样行吗?
我这是不论焦点在哪个Text
只要Text中含有内容时,复制才可以用。

其实这也是按照Windows的设计。
有内容时,复制按钮可以用。(同理,有内容时,剪切才可以用)当触发了复制事件后,粘帖按钮才可以用。
Dim which As Integer, T As Integer

Private Sub copy_Click()
If which = 1 Then
T = Text1.Text
ElseIf which = 2 Then
T = Text2.Text
End If
End Sub

Private Sub cut_Click()
If which = 1 Then
T = Text1.Text
Text1.Text = ""
ElseIf which = 2 Then
T = Text2.Text
Text2.Text = ""
End If
End Sub

Private Sub edit_Click()
If which = 1 Then
If Text1.Text = "" Then
cut.Enabled = False
copy.Enabled = False
Else
cut.Enabled = True
copy.Enabled = True
End If
ElseIf which = 2 Then
If T = "" Then
cut.Enabled = False
copy.Enabled = False
Else
cut.Enabled = True
copy.Enabled = True
End If
End If
If T = "" Then
paste.Enabled = False
Else
paste.Enabled = True
End If
End Sub

Private Sub paste_Click()
If which = 1 Then
Text1.Text = Text1 + T
ElseIf which = 2 Then
Text2.Text = Text2 + T
End If
End Sub

Private Sub Text1_GotFocus() '本过程的作用是:当焦点在Text1中时,which = 1
which = 1
End Sub

Private Sub Text2_GotFocus() '本过程的作用是:当焦点在Text2中时,which = 2
which = 2
End Sub

回答2:

Clipboard.SetText text1.text'把text1的内容到剪贴板