VB.Net程序设计:拖放数据操作-从ListBox中拖放数据到ListBox 中

VB.Net程序设计:从ListBox中拖放数据到ListBox 中。(VS2005)

运行界面图:

从ListBox中拖放数据到ListBox 中

 

代码:

 

Public Class FrmList2List
    
Dim i As Integer

    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
Me.Close()
    
End Sub


    
Private Sub Form3_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load
        
For i = 1 To 5
            
Me.ListBox1.Items.Add(i)
        
Next
        
For i = 6 To 9
            
Me.ListBox2.Items.Add(i)
        
Next
        ListBox1.AllowDrop 
= True
        ListBox2.AllowDrop 
= True
    
End Sub


    
Private Sub ListBox1_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
        
If e.Button = Windows.Forms.MouseButtons.Left Then
            
If ListBox1.SelectedItem IsNot Nothing Then
                
Me.ListBox1.DoDragDrop(Me.ListBox1.SelectedItem.ToString, DragDropEffects.Copy)
                
Me.Label1.Text = "启动拖放数据..." & Me.ListBox1.SelectedItem
            
Else
                
Me.Label1.Text = ""
            
End If
        
End If
    
End Sub


    
Private Sub ListBox2_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
        
If (e.Data.GetDataPresent(DataFormats.Text)) Then
            
Me.Label1.Text = "有数据拖进来...托..."
            e.Effect 
= DragDropEffects.Copy
        
Else
            e.Effect 
= DragDropEffects.None
            
Me.Label1.Text = ""
        
End If
    
End Sub


    
Private Sub ListBox2_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
        
If e.Data.GetDataPresent(DataFormats.Text) Then
            
Me.ListBox2.Items.Add(e.Data.GetData(DataFormats.Text))
            
Me.Label1.Text = "有数据放进来...放..."
        
End If
    
End Sub


    
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        
Me.Label1.Text = ""
    
End Sub


    
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        
Me.ListBox1.ClearSelected()
    
End Sub


End Class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值