Cambiar la imagen de múltiples cuadros dinámicos
Estoy haciendo una lista de contactos con VB.NET con imágenes de estado. Estoy cargando esta lista desde MSSQL pero cuando vuelvo a cargar la lista parpadea.
Esta lista es un TableLayoutPanel con cuadros y etiquetas dinámicos creados.
Mi pregunta es:
¿Cómo puedo cambiar mi imagen dentro de un cuadro de imagen dinámico cuando vuelvo a cargar mis contactos en lugar de volver a cargar la lista completa?
Mi código para crear la tabla:
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
Imagen de mi lista de contactos