منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
ListBox DragDrop تعديل هذا الكود - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : ListBox DragDrop تعديل هذا الكود (/showthread.php?tid=8155)



ListBox DragDrop تعديل هذا الكود - محمد - 26-03-13

كيف عمل ListBox DragDrop لى صيغة معيبة وليس لى جميع الصغات بمعنى مثلآ لو الملف صيغة jpg يتم DragDrop غير كده لا يتم
او ممكن تعديل هذا الكود
كود :
Dim fileinfo As IO.FileInfo

    Dim MyFiles() As String
    Dim MyNames() As String
    Private Sub ListBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim i As Integer
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            MyNames = e.Data.GetData(DataFormats.FileDrop)
            Dim name As String
            For i = 0 To MyFiles.Length - 1
                fileinfo = New IO.FileInfo(MyNames(i))
                name = fileinfo.Name.Remove(fileinfo.Name.Length - 4, 4)
                ListBox2.Items.Add(name)
            Next
            For i = 0 To MyFiles.Length - 1
                ListBox1.Items.Add(MyFiles(i))
            Next
        End If
    End Sub

    Private Sub ListBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub
هذا الموود يتم اضافه جميع الصيغات انا اريده صيغة محدوده فقط
شكرآ


ListBox DragDrop تعديل هذا الكود - Sajad - 26-03-13

السلام عليكم

اعتقد الحل من خلال هذا الكود في الDragEnter

PHP كود :
If (e.Data.GetDataPresent(TypeOf e.Data Is Imaging.ImageFormat)) Then
            e
.Effect DragDropEffects.All
        End 
If 



ListBox DragDrop تعديل هذا الكود - محمد - 26-03-13

sajad كتب :السلام عليكم

اعتقد الحل من خلال هذا الكود في الDragEnter

PHP كود :
If (e.Data.GetDataPresent(TypeOf e.Data Is Imaging.ImageFormat)) Then
            e
.Effect DragDropEffects.All
        End 
If 
جزاك الله خير شكرآ اخى
هل يمكن ايضآ مع الملفات الصوتية وى exe و ملفات الفيديو ?
جربت بى وضع Extension.ExtensionFormat
و Midea.MideaFormat
ولم ينفع


ListBox DragDrop تعديل هذا الكود - @@أبورائد@@ - 26-03-13


السلام عليكم ورحمة الله وبركاته






هذا مثال لادراج ملفات حسب انواع محدد







السلام عليكم ورحمة الله وبركاته



ListBox DragDrop تعديل هذا الكود - RainBow - 26-03-13

هذا هو الكود المطلوب
كود :
Dim s() As String = e.Data.GetData("FileDrop", False)
        Dim i As Integer
        Dim AllowedTypes As String = ".jpg .mp3 .exe"
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            MyNames = e.Data.GetData(DataFormats.FileDrop)
            Dim name As String
            For i = 0 To MyFiles.Length - 1
                If AllowedTypes.Contains(Path.GetExtension(s(i))) Then
                    fileinfo = New IO.FileInfo(MyNames(i))
                    name = fileinfo.Name.Remove(fileinfo.Name.Length - 4, 4)
                    ListBox2.Items.Add(name)
                End If
            Next
            For i = 0 To MyFiles.Length - 1
                If AllowedTypes.Contains(Path.GetExtension(s(i))) Then
                    ListBox1.Items.Add(MyFiles(i))
                End If
            Next
        End If



ListBox DragDrop تعديل هذا الكود - محمد - 26-03-13

sajad كتب :السلام عليكم

اعتقد الحل من خلال هذا الكود في الDragEnter

PHP كود :
If (e.Data.GetDataPresent(TypeOf e.Data Is Imaging.ImageFormat)) Then
            e
.Effect DragDropEffects.All
        End 
If 

محمد كتب :جزاك الله خير شكرآ اخى
هل يمكن ايضآ مع الملفات الصوتية وى exe و ملفات الفيديو ?
جربت بى وضع Extension.ExtensionFormat
و Midea.MideaFormat
ولم ينفع

RainBow كتب :هذا هو الكود المطلوب
كود :
Dim s() As String = e.Data.GetData("FileDrop", False)
        Dim i As Integer
        Dim AllowedTypes As String = ".jpg .mp3 .exe"
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            MyNames = e.Data.GetData(DataFormats.FileDrop)
            Dim name As String
            For i = 0 To MyFiles.Length - 1
                If AllowedTypes.Contains(Path.GetExtension(s(i))) Then
                    fileinfo = New IO.FileInfo(MyNames(i))
                    name = fileinfo.Name.Remove(fileinfo.Name.Length - 4, 4)
                    ListBox2.Items.Add(name)
                End If
            Next
            For i = 0 To MyFiles.Length - 1
                If AllowedTypes.Contains(Path.GetExtension(s(i))) Then
                    ListBox1.Items.Add(MyFiles(i))
                End If
            Next
        End If
جزاكم الله خير اخوتى
هذا الذى احتاجة اخى Rain
أبورائد لماذا لا يظهر زر الشكر و الاعجاب عندك !