Sürükle Bırak (Drag-Drop)
Bu örnekte resimlere ait dosya yollarını listbox a sürükle bırak metodu ile ekleyeceğiz. Daha sonra listbox taki seçili itemsteki image i PictureBox ta göstereceğiz. Aşağıdaki şekilleri inceleyin.
Formunuza 1 adet ListBox,PictureBox ve 2 adet Label ekleyin.
Şekil 1
Şekil 2
Public Class Form1
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
If CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".bmp") = True Or CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".jpg") = True Or CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".jpeg") = True Or CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".gif") = True Then
ListBox1.SelectedIndex = ListBox1.Items.Add(CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0))
End If
End Sub
Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
e.Effect = e.AllowedEffect
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
If CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".bmp") = True Or CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".jpg") = True Or CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".jpeg") = True Or CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0).Endswith(".gif") = True Then
ListBox1.Items.Add(CType(e.Data.GetData(DataFormats.FileDrop), System.Array)(0))
End If
End Sub
Private Sub ListBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
e.Effect = e.AllowedEffect
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
PictureBox1.ImageLocation = ListBox1.SelectedItem.ToString
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
End Class
Bir sonraki makalede buluşmak üzere. Bahadır ŞAHİN