当前位置:编程学习 > VB >>

vb中如何实现文件拖动复制

主要是用控件file时从file1拖住文件复制在file2中如何实现,编码是
什么?
答案:
给你个例子把:
'''窗体上需要DriveListBox,DirListBox和FileListBox各2个,名称保留默认名称
Option Explicit
Dim fcpy As Boolean '标记是否是从file1托过来的文件

Private Sub Dir1_Change()
  File1.Path = Dir1.Path
End Sub

Private Sub Dir2_Change()
  File2.Path = Dir2.Path
End Sub

Private Sub Drive1_Change()
  Dir1.Path = Drive1.Drive
End Sub

Private Sub Drive2_Change()
  Dir2.Path = Drive2.Drive
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 Dir1.Path & "\" & File1.FileName, Dir2.Path & "\" & File1.FileName '复制文件
    fcpy = False
    File2.Refresh '刷新列表
  End If
End Sub

Private Sub Form_Load()
  File1.OLEDragMode = 1
  File1.OLEDropMode = 1
  File2.OLEDragMode = 1
  File2.OLEDropMode = 1
End Sub

上一个:VB基础题,急!!!高手来帮忙!!!
下一个:vb.net怎么做中文语音识别程序

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,