منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : كيفية منع تكرار ملف مرتبط بزر ديناميكي
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم
لديا فلو ليوت بنل به مجموعة من الازرار المستحدثة  الغير مفعلة بمثاية قائمة ملفات يتم اخيارها عن طريق اوبن فايل ديالوج
يتم تفعيل عدد من الازاز العير مفعلة حسب عدد الملفات المختارة عن طريق الاوبن فايل
سؤالي هنا كيف استطيع منع اختيار نفس الملف مرة اخرى اذا كان الزر المناط به مفغل وعند اختيار ملف مكرر يتم حذفه مع تحديده
و للتوضيح اكثر سارفق مثال بسيط لكيقية استحداث الازراز و تفعيلها حسب عدد الملفات المخنارة
و شكرا مسبقا
كود :
Public Class Form1
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Dim btnSize = New Size(25, 15)
        For i = 1 To 16
            Dim btn As New Button With {.Text = i, .Size = btnSize, .Enabled = False}
            btn.UseVisualStyleBackColor = True
            btn.Font = New Font("Microsoft Sans Serif", 5.0F)
            btn.Margin = New Padding(0)
            AddHandler btn.Click, AddressOf Bouton_Click
            Me.FlowLayoutPanel1.Controls.Add(btn)
        Next
        FlowLayoutPanel1.AutoSize = False
        FlowLayoutPanel1.AutoScroll = False
        FlowLayoutPanel1.Width = (btnSize.Width * 5)
        FlowLayoutPanel1.Height = (btnSize.Height * 3)
    End Sub
    Private Sub Bouton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim btn As Button = sender
        MsgBox("you have clicked : button " & btn.Text & vbNewLine & IO.Path.GetFileName(btn.Tag))
    End Sub
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim OpenFile As New OpenFileDialog With {.Multiselect = True}
        If OpenFile.ShowDialog() = DialogResult.OK Then
            Dim buttons = Me.FlowLayoutPanel1.Controls.OfType(Of Button)()
            For Each fn As String In OpenFile.FileNames
                If buttons.Any(Function(x) x.Tag = fn) Then Continue For
                Dim btn = buttons.FirstOrDefault(Function(b) b.Enabled = False)
                If btn Is Nothing Then Exit For
                btn.Enabled = True
                btn.BackColor = Color.Turquoise
                btn.Tag = fn
            Next
        End If
    End Sub
End Class
(11-01-22, 05:07 PM)E100 كتب : [ -> ]
كود :
Public Class Form1
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
       Dim btnSize = New Size(25, 15)
       For i = 1 To 16
           Dim btn As New Button With {.Text = i, .Size = btnSize, .Enabled = False}
           btn.UseVisualStyleBackColor = True
           btn.Font = New Font("Microsoft Sans Serif", 5.0F)
           btn.Margin = New Padding(0)
           AddHandler btn.Click, AddressOf Bouton_Click
           Me.FlowLayoutPanel1.Controls.Add(btn)
       Next
       FlowLayoutPanel1.AutoSize = False
       FlowLayoutPanel1.AutoScroll = False
       FlowLayoutPanel1.Width = (btnSize.Width * 5)
       FlowLayoutPanel1.Height = (btnSize.Height * 3)
   End Sub
   Private Sub Bouton_Click(ByVal sender As Object, ByVal e As EventArgs)
       Dim btn As Button = sender
       MsgBox("you have clicked : button " & btn.Text & vbNewLine & IO.Path.GetFileName(btn.Tag))
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
       Dim OpenFile As New OpenFileDialog With {.Multiselect = True}
       If OpenFile.ShowDialog() = DialogResult.OK Then
           Dim buttons = Me.FlowLayoutPanel1.Controls.OfType(Of Button)()
           For Each fn As String In OpenFile.FileNames
               If buttons.Any(Function(x) x.Tag = fn) Then Continue For
               Dim btn = buttons.FirstOrDefault(Function(b) b.Enabled = False)
               If btn Is Nothing Then Exit For
               btn.Enabled = True
               btn.BackColor = Color.Turquoise
               btn.Tag = fn
           Next
       End If
   End Sub
End Class

تمام التمام .... اتم الله عليك بوافر النعم و كفاك شر النقم
الف شكر اخي الكريم