vb.net文件移动 vbnet format( 二 )


于是我们在程序加载的时候 调用Application AddMessageFilter(Me) 然而 默认情况下一个Form或者控件是不能接受拖放的文件的 我们调用一个WIN API DragAcceptFiles源码天空 这个API可以设置对应的控件是否能接受拖放的文件 然后可以用DragQueryFile查询拖放到的文件列表 也就是拖放文件地具体路径和文件名
代码
Imports System Runtime InteropServices
Public Class Form
Inherits System Windows Forms Form
Implements IMessageFilter
API申明
Const WM_DROPFILES = H拖放文件消息
DllImport( shell dll ) Public Shared Sub DragFinish(ByVal hDrop As Integer)
End Sub
DllImport( shell dll ) Public Shared Sub DragAcceptFiles(ByVal hwnd As Integer ByVal fAccept As Boolean)
End Sub
DllImport( shell dll ) Public Shared Function DragQueryFile(ByVal HDROP As Integer ByVal UINT As Integer ByVal lpStr As System Text StringBuilder ByVal ch As Integer) As Integer
End Function
Private Sub Form _Load(ByVal sender As System Object ByVal e As System EventArgs) Handles MyBase Load
Application AddMessageFilter(Me)
DragAcceptFiles(TextBox Handle ToInt True)
End Sub
Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter PreFilterMessage
If m Msg = WM_DROPFILES Then
设置拖放的动作
Dim nfiles As Int
nfiles = DragQueryFile(m WParam ToInt Nothing )
Dim i As Int
Dim *** As New System Text StringBuilder( )
Dim sFirstFileName As String 记录第一个文件名
TextBox Clear()
For i = To nfiles
DragQueryFile(m WParam ToInt i *** )
If i = Then sFirstFileName = *** ToString
TextBox AppendText(ControlChars CrLf*** ToString)
Next
DragFinish(m WParam ToInt ) 拖放完成
显示文件内容
Dim fs As New System IO FileStream(sFirstFileName IO FileMode Open)
Dim sr As New System IO StreamReader(fs System Text Encoding GetEncoding( gb ))
TextBox AppendText(ControlChars CrLfsr ReadToEnd() ToString)
fs Close()
sr Close()
End If
Return False
End Function
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (ponents Is Nothing) Then
ponents Dispose()
End If
End If
Application RemoveMessageFilter(Me)
DragAcceptFiles(TextBox Handle ToInt False)
MyBase Dispose(disposing)
End Sub
lishixinzhi/Article/program/net/201311/13043
VB.NET 怎么将FTP文件移动到FTP下另一个目录中去给vb.net文件移动你个方法原型:
File.Copy("~\*.*","~\",Boolean)第一个参数是String,指定原文件vb.net文件移动的Path;
第二个参数是String,指定拷贝目标Path;
第三个参数是Booleanvb.net文件移动,表示覆盖同名文件 。
自己修改一下即可 。
【vb.net文件移动 vbnet format】vb.net文件移动的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet format、vb.net文件移动的信息别忘了在本站进行查找喔 。

推荐阅读