Ändern Sie das Bild aus mehreren dynamischen Bildfeldern
Ich erstelle mit VB.NET eine Kontaktliste mit Statusbildern. Ich lade diese Liste von MSSQL, aber wenn ich die Liste neu lade, flackert sie.
Diese Liste ist ein TableLayoutPanel mit dynamisch erstellten Bildboxen und Beschriftungen.
Meine Frage ist
Wie kann ich mein Bild in einer dynamischen Bilderbox ändern, wenn Sie meine Kontakte neu laden, anstatt die gesamte Liste neu zu laden?
Mein Code zum Erstellen der Tabelle:
While UserData.Read
If UserData("Status").ToString = "Online" Then
If UserData("NieuwBericht").ToString = "Ja" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.greenchat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox)
Dim newPictureBox2 As New PictureBox
newPictureBox2.Image = My.Resources.greenbubblechat
newPictureBox2.Visible = True
newPictureBox2.Width = 30
newPictureBox2.Height = 30
newPictureBox2.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox2.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox2)
Dim newLabel As New Label
AddHandler newLabel.Click, AddressOf Chatbox
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Dock = DockStyle.Fill
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
ElseIf UserData("NieuwBericht").ToString = "Nee" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.greenchat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox)
Dim newPictureBox2 As New PictureBox
newPictureBox2.Image = My.Resources.greybubblechat
newPictureBox2.Visible = True
newPictureBox2.Width = 30
newPictureBox2.Height = 30
newPictureBox2.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox2.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox2)
Dim newLabel As New Label
AddHandler newLabel.Click, AddressOf Chatbox
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Dock = DockStyle.Fill
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
End If
ElseIf UserData("Status").ToString = "Afwezig" Then
If UserData("NieuwBericht").ToString = "Ja" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.orangechat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox)
Dim newPictureBox2 As New PictureBox
newPictureBox2.Image = My.Resources.greenbubblechat
newPictureBox2.Visible = True
newPictureBox2.Width = 30
newPictureBox2.Height = 30
newPictureBox2.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox2.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox2)
Dim newLabel As New Label
AddHandler newLabel.Click, AddressOf Chatbox
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Dock = DockStyle.Fill
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
ElseIf UserData("NieuwBericht").ToString = "Nee" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.orangechat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox)
Dim newPictureBox2 As New PictureBox
newPictureBox2.Image = My.Resources.greybubblechat
newPictureBox2.Visible = True
newPictureBox2.Width = 30
newPictureBox2.Height = 30
newPictureBox2.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox2.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox2)
Dim newLabel As New Label
AddHandler newLabel.Click, AddressOf Chatbox
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Dock = DockStyle.Fill
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
End If
ElseIf UserData("Status").ToString = "Offline" Then
If UserData("NieuwBericht").ToString = "Ja" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.redchat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox)
Dim newPictureBox2 As New PictureBox
newPictureBox2.Image = My.Resources.greenbubblechat
newPictureBox2.Visible = True
newPictureBox2.Width = 30
newPictureBox2.Height = 30
newPictureBox2.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox2.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox2)
Dim newLabel As New Label
AddHandler newLabel.Click, AddressOf Chatbox
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Dock = DockStyle.Fill
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
ElseIf UserData("NieuwBericht").ToString = "Nee" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.redchat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox)
Dim newPictureBox2 As New PictureBox
newPictureBox2.Image = My.Resources.greybubblechat
newPictureBox2.Visible = True
newPictureBox2.Width = 30
newPictureBox2.Height = 30
newPictureBox2.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox2.Name = UserData("Username").ToString
ChatContactList.Controls.Add(newPictureBox2)
Dim newLabel As New Label
AddHandler newLabel.Click, AddressOf Chatbox
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Dock = DockStyle.Fill
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
End If
End If
End While
Bild meiner Kontaktliste