窗体中有一个:ListView1,4个TextBox:TextBox1,TextBox2,TextBox3,TextBox4。一个ComboBox1。
注意设置4个:TextBox的:AllowDrop 为True。
运行界面图:
代码如下:
Public Class FrmSelTipS Private Sub TextBoxS_DragDrop(ByVal sender As Object,ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop,TextBox2.DragDrop,TextBox3.DragDrop,TextBox4.DragDrop If e.Data.GetDataPresent(DataFormats.Text) Then '同一类控件触发同一类事件。事件:DragDrop If CType(sender,TextBox).Name = Me.TextBox1.Name Then Me.TextBox1.Text = e.Data.GetData(DataFormats.Text) End If If CType(sender,TextBox).Name = Me.TextBox2.Name Then Me.TextBox2.Text = e.Data.GetData(DataFormats.Text) End If If CType(sender,TextBox).Name = Me.TextBox3.Name Then Me.TextBox3.Text = e.Data.GetData(DataFormats.Text) End If If CType(sender,TextBox).Name = Me.TextBox4.Name Then Me.TextBox4.Text = e.Data.GetData(DataFormats.Text) End If End If End Sub Private Sub TextBoxS_DragEnter(ByVal sender As System.Object,ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter,TextBox2.DragEnter,TextBox3.DragEnter,TextBox4.DragEnter '同一类控件触发同一类事件。事件:DragEnter e.Effect = DragDropEffects.Copy End Sub Private Sub ListView1_MouseDown(ByVal sender As System.Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown If Me.ListView1.SelectedItems.Count > 0 Then '启动拖放数据 Me.ListView1.DoDragDrop(Me.ListView1.SelectedItems(0).SubItems(0).Text,DragDropEffects.Copy) End If End Sub Private Sub FrmSelTipS_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To 10 Me.ListView1.Items.Add(i.ToString,i.ToString,0) Next Me.ComboBox1.Items.Add(View.LargeIcon) Me.ComboBox1.Items.Add(View.Details) Me.ComboBox1.Items.Add(View.SmallIcon) Me.ComboBox1.Items.Add(View.List) Me.ComboBox1.Items.Add(View.Tile) Me.ComboBox1.SelectedIndex = 0 End Sub Private Sub Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object,ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Me.ListView1.View = Me.ComboBox1.SelectedIndex End Sub End Class