11-01-22, 05:07 PM
كود :
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