| VB.NET (リストボックスのAllowDropプロパティをTrueに設定しておくこと) | |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 |
Private Sub listBoxFiles_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles listBoxFiles.DragDrop ' 格納されているデータを文字列型配列に変換 Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop, False), String()) listBoxFiles.BeginUpdate() listBoxFiles.Items.Clear() listBoxFiles.Items.AddRange(files) listBoxFiles.EndUpdate() End Sub Private Sub listBoxFiles_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles listBoxFiles.DragEnter ' 格納されているデータの形式を確認する If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub |
| C# (リストボックスのAllowDropプロパティをTrueに設定しておくこと) | |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 |
private void listBoxFiles_DragDrop( object sender, System.Windows.Forms.DragEventArgs e ) { // 格納されているデータを文字列型配列に変換 string[] files = (string[])e.Data.GetData( DataFormats.FileDrop, false ); listBoxFiles.BeginUpdate(); listBoxFiles.Items.Clear(); listBoxFiles.Items.AddRange( file ); listBoxFiles.EndUpdate(); } private void listBoxFiles_DragEnter( object sender, System.Windows.Forms.DragEventArgs e ) { // 格納されているデータの形式を確認する if ( e.Data.GetDataPresent( DataFormats.FileDrop ) ) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } |