VB怎么实现按一个按钮就把文本筐内的文字复制

VB怎么实现按一个按钮就把文本筐内的文字复制,第1张

command1_click事件中写以下代码:
clipboardsettext text1text
全部代码:
Private Sub Command1_Click()
ClipboardSetText Text1Text
End Sub

Private Sub CmdCopy_Click()
ClipboardSetText TxtContentSelText
End Sub
Private Sub CmdPaste_Click()
TxtContentSelText = ClipboardGetText
End Sub
Private Sub CmdCopy_Click()
'这只是按钮代码的起始而已,按钮名叫做CmdCopy,事件是单击
ClipboardSetText TxtContentSelText
'Clipboard指剪贴板;SetText是剪贴板对象的一个方法,用来设置剪贴板的内容;TxtContent是指一个文本框;SelText是文本框的一个属性,指文本框的内容
'翻译过来就是把剪贴板的内容设为文本框的内容,就是复制(因为原内容并没有消失,要实现剪切,在这句后面加一句TxtContentSelText = "")
End Sub
'代码完毕
Private Sub CmdPaste_Click()
'按钮名叫CmdPaste,事件是单击
TxtContentSelText = ClipboardGetText
'TxtContentSelText参见上文。Clipboard仍然指剪贴板,GetText指剪贴板的内容,是一个属性)
'翻译过来就是把文本框的内容设为剪贴板的内容,就是粘贴了
End Sub
'代码完毕

实现方法如下:
1、在窗体form1中放置两个文本框,Text1和Text2;
2、代码如下:(当然,这是简单的示例,你可据要求做变通处理,但原理是一样的:控件焦点的转移),祝你成功!
Dim a As String
Private Sub Text1_GotFocus()

Text1Text = Text1Text & a

End Sub
Private Sub Text1_LostFocus()

a = Trim$(Text1Text)

End Sub
Private Sub Text2_GotFocus()

Text2Text = Text2Text & a

End Sub
Private Sub Text2_LostFocus()

a = Trim$(Text2Text)

End Sub

给你个例子把: '''窗体上需要DriveListBox,DirListBox和FileListBox各2个,名称保留默认名称 Option Explicit Dim fcpy As Boolean '标记是否是从file1托过来的文件 Private Sub Dir1_Change() File1Path = Dir1Path End Sub Private Sub Dir2_Change() File2Path = Dir2Path End Sub Private Sub Drive1_Change() Dir1Path = Drive1Drive End Sub Private Sub Drive2_Change() Dir2Path = Drive2Drive End Sub Private Sub File1_OLEStartDrag(Data As DataObject, AllowedEffects As Long) fcpy = True End Sub Private Sub File2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) If fcpy Then '如果为file1托来的 FileCopy Dir1Path & "\" & File1FileName, Dir2Path & "\" & File1FileName '复制文件 fcpy = False File2Refresh '刷新列表 End If End Sub Private Sub Form_Load() File1OLEDragMode = 1 File1OLEDropMode = 1 File2OLEDragMode = 1 File2OLEDropMode = 1 End Sub

FileCopy replace(apppath & "\" & appexename,"\\","\"),replace("C:\456\" & appexename,"\\","\")
这样就可以了```
apppath & "\" & appexename & "exe"的结果是程序本身的完全路径,也许有人会说为什么不直接写apppath & appexename & "exe",因为这样写会有2个可能性:
1假设文件在如C:\aaa的目录下,程序文件名为bbbexe,``这样的话
apppath & appexename & "exe"得出的结果为c:\aaabbbexe,这样是错误的,而apppath & "\" & appexename & "exe"的结果才是正确的c:\aaa\bbbexe
2如果文件在c:\下,程序文件名为bbbexe,这样apppath & appexename & "exe"得出的结果就是C:\bbbexe,是真确的,而apppath & "\" & appexename & "exe"又会得出错误的结果C:\\bbbexe
所以为了使程序在以上2个可能性的时候都能正确运行``这样写
replace(apppath & "\" & appexename,"\\","\")
这样的话可以把apppath & "\" & appexename所得结果中所有的\\替换为\,就可以避免错误````


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13162892.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-14
下一篇 2023-06-14

发表评论

登录后才能评论

评论列表(0条)

保存