Dim copyfile As String '取文件路径的变量
Dim getname As String '取文件名的变量
Private Sub copy1_Click() '菜单的 复制 子菜单的事件
copyfile = File1.Path & File1.FileName '取文件路径
getname = File1.FileName '取文件名
End Sub
Private Sub del4_Click() '菜单的 删除 子菜单的事件
Kill Dir1.Path & "\" & File1.FileName '删除文件
File1.Refresh '更新文件列表框
End Sub
Private Sub Dir1_Change() '
File1.Path = Dir1.Path '
End Sub
Private Sub Drive1_Change() '
Dir1.Path = Drive1.Drive '
End Sub
 'filelistbox的弹出式菜单事件
Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyRButton Then PopupMenu menu '点击鼠标右键调用PopupMenu方法弹出 menu 的下级子菜单
End Sub
Private Sub jt2_Click() '菜单的 粘贴 子菜单的事件
Set fs = CreateObject("Scripting.FileSystemObject") '
fs.FileCopy copyfile, Dir1.Path & "\" & getname '复制→粘贴 动作。此行出错 “对象不支持该属性或方法”
'可能是文件列表框(filelistbox)控件不支持该属性或方法,请问要怎样才能解决这个问题呢?
'怎样让鼠标没处当前选中的项目时,点右键不能弹出子菜单?
End Sub

解决方案 »

  1.   

    结合Clipboard对象弄复制好一点,起码可以多复制点东西
      

  2.   


    更改为Private Sub jt2_Click() '菜单的 粘贴 子菜单的事件
        FileCopy copyfile, Dir1.Path & "\" & getname '复制→粘贴 动作。
    End Sub
      

  3.   

    同意楼上,复制一个文件而已,用VB内置的filecopy就行了。
      

  4.   

    第一个问题同意2楼
    第二个问题'怎样让鼠标没处当前选中的项目时,点右键不能弹出子菜单?
    看你写的事件在什么地方发生的,,你是File1_MouseDown,那么就在file1下触发
      

  5.   

    我测试过了,用2楼的办法,会提示找不到文件。
    help me
      

  6.   

    copyfile = File1.Path & File1.FileName
    改为:
    copyfile=file1.path & "\" & file1.filename
      

  7.   

    你的用法出错:
    fs.FileCopy copyfile, Dir1.Path & "\" & getname '复制→粘贴 动作。此行出错 “对象不支持该属性或方法”
    改为:
    fs.CopyFile copyfile, Dir1.Path & "\" & getname '复制→粘贴 动作。这样就对了。
      

  8.   

    为了保险起见,这样:
    copyfile = File1.Path & File1.FileName '取文件路径
    改为:
    copyfile =iif(right(File1.Path,1)="\",File1.Path & File1.FileName ,File1.Path &"\"& File1.FileName) '取文件路径
    Dir1.Path & "\" & getname 改为:
    iif(right(Dir1.Path,1)="\",Dir1.Path & getname ,Dir1.Path & "\" & getname)