vb.net拖放文件 vba拖拽文件( 二 )


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拖放文本文件到TextBox获得其路径 。Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.AllowDrop = True
End Sub
Private Sub TextBoxDragEnter(sender As Object, e As DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files As String()
Try
files = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.TextBox1.Text = files(files.Length - 1)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
End Sub
TextBox1.AllowDrop = True 是开启拖放支持vb.net拖放文件,可以在窗体设计器里面开启它vb.net拖放文件,也可以代码开启 。
vb.net textbox1选中的文本,拖放到textbox2?很久没有上这里了,今天看到了这个问题,尝试做了一个;
本例以源文本框TextBox1全部文字作为拖放文字为例,实现拖放
1、向一个窗体中添加两个文本框 , 分别名为TextBox1,TextBox2 。注意:把TextBox2控件的AllowDrop属性设置成True , 这点不要遗漏 。
2、完整的代码如下:
Public Class Form1
Private MouseIsDown As Boolean = False
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
'设置一个标志以显示鼠标已按下 。
MouseIsDown = True
End Sub
Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
If MouseIsDown Then
'开始拖动(将TextBox1的文本内容作为拖放内容) 。
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
'检查正在被拖放的数据的格式 。
If (e.Data.GetDataPresent(DataFormats.Text)) Then
'显示复制光标(表示是拖放行为) 。
e.Effect = DragDropEffects.Copy
Else
'显示不放置光标(表示不是拖放行为) 。
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
'粘贴文本(将拖放内容作为TextBox2的文本内容) 。
TextBox2.Text = e.Data.GetData(DataFormats.Text)
End Sub
End Class
【vb.net拖放文件 vba拖拽文件】vb.net拖放文件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vba拖拽文件、vb.net拖放文件的信息别忘了在本站进行查找喔 。

推荐阅读