1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ListBox1.Items.Clear()
ImgList.Images.Clear()
Dim ListImage As IEnumerable(Of ChainesData) = (From c As ChainesData In Chaines Where c.LogoURL = ComboBox1.Text Select c).Distinct.ToArray
If ListImage.Count > 0 Then
ImgList.Images.Add(ChargerImage(ListImage.ToString), Color.Transparent)
Else
ImgList.Images.Add(My.Resources.pngwing_com, Color.Transparent)
End If
ListBox1.Items.AddRange((From chn As ChainesData In Chaines Where chn.GroupTitle = ComboBox1.Text Select chn).Distinct.ToArray)
End Sub
Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground()
Dim drawDefautFont As Font = e.Font
Dim ourFont As Boolean = False
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
ourFont = True
drawDefautFont = New Font(drawDefautFont, FontStyle.Bold)
End If
If e.Index <> -1 Then
e.Graphics.DrawImage(ImgList.Images(e.Index).Clone, New Rectangle(e.Bounds.X + (ListBox1.Width / 4.4), e.Bounds.Y - 1, e.Bounds.Height, e.Bounds.Height))
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), drawDefautFont, New SolidBrush(e.ForeColor), e.Bounds, New StringFormat With {.Alignment = StringAlignment.Center})
End If
If ourFont Then drawDefautFont.Dispose()
e.DrawFocusRectangle()
End Sub
Private Function ChargerImage(ByVal Liens As String) As Image
Dim client As New WebClient()
Using str As Stream = client.OpenRead(Liens)
Return Image.FromStream(str)
End Using
End Function |
Partager