vb.net文件拖拽 vbnet tooltip

VB.NET的ListBox怎样实现项目可以拖动追问:额,没有学过C#回答:一样的Imports System.Drawing Imports System.Collections Imports System.ComponentModel Imports System.Windows.Forms Imports System.Data Namespace WindowsApplication2 Public Class Form1 Inherits System.Windows.Forms.Form Private listBox1 As System.Windows.Forms.ListBox Private indexofsource As Integer '拖动的起始索引 Private indexoftarget As Integer '拖动的结束索引 Private components As System.ComponentModel.Container = Nothing Public Sub New() InitializeComponent() End Sub Protected Overrides Sub Dispose(disposing As Boolean) If disposing Then If components IsNot Nothing Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private Sub InitializeComponent() Me.listBox1 = New System.Windows.Forms.ListBox() Me.SuspendLayout() ' ' listBox1 ' Me.listBox1.AllowDrop = True '这个属性一定要设置为true; Me.listBox1.ItemHeight = 12 Me.listBox1.Items.AddRange(New Object() {"1", "2", "3", "4", "5", "6", _ "7", "8", "9", "0"}) Me.listBox1.Location = New System.Drawing.Point(16, 8) Me.listBox1.Name = "listBox1" Me.listBox1.ScrollAlwaysVisible = True Me.listBox1.Size = New System.Drawing.Size(264, 136) Me.listBox1.TabIndex = 0 AddHandler Me.listBox1.MouseDown, New System.Windows.Forms.MouseEventHandler(AddressOf Me.listBox1_MouseDown) AddHandler Me.listBox1.DragOver, New System.Windows.Forms.DragEventHandler(AddressOf Me.listBox1_DragOver) AddHandler Me.listBox1.DragDrop, New System.Windows.Forms.DragEventHandler(AddressOf Me.listBox1_DragDrop) Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.listBox1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub STAThread _ Private Shared Sub Main() Application.Run(New Form1()) End Sub Private Sub listBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) indexofsource = DirectCast(sender, ListBox).IndexFromPoint(e.X, e.Y) If indexofsourceListBox.NoMatches Then DirectCast(sender, ListBox).DoDragDrop(DirectCast(sender, ListBox).Items(indexofsource).ToString(), DragDropEffects.All) End If End Sub Private Sub listBox1_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) '拖动源和放置的目的地一定是一个ListBox If e.Data.GetDataPresent(GetType(System.String)) AndAlso DirectCast(sender, ListBox).Equals(listBox1) Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Private Sub listBox1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Dim listbox__1 As ListBox = DirectCast(sender, ListBox) indexoftarget = listbox__1.IndexFromPoint(listbox__1.PointToClient(New Point(e.X, e.Y))) If indexoftargetListBox.NoMatches Then Dim temp As String = listbox__1.Items(indexoftarget).ToString() listbox__1.Items(indexoftarget) = listbox__1.Items(indexofsource) listbox__1.Items(indexofsource) = temp listbox__1.SelectedIndex = indexoftarget End If End Sub End Class End Namespace
vb.net 如何拖动文件打开exe文件可以直接拖吧,拖动文件到exe文件上,exe文件就会自动打开 。command接收拖动的文件路径 。
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 如何实现拖拽打一个AjaxControlToolkit补丁包
里面有很多控件
就有你想要的拖拽控件
求助vb.net拖拽文件到窗体获取文件信息这是一个简单vb.net文件拖拽的示例vb.net文件拖拽 , 你只需要新建一个项目vb.net文件拖拽,并在项目上放置一个文本框vb.net文件拖拽:TEXTBOX1,然后,将以下代码复制到代码区:
【vb.net文件拖拽 vbnet tooltip】Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True
End Sub
''建拖曳事件 , 实现文件拖放
Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
Dim filepaht As String() = e.Data.GetData(DataFormats.FileDrop)
For Each File As String In filepaht
textBox1.Text = File
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
如此,在文本框里将会出现被拖曳文件的路径信息 。
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文件拖拽的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet tooltip、vb.net文件拖拽的信息别忘了在本站进行查找喔 。

    推荐阅读