I'm making a contactlist with VB.NET with status images. I'm loading this list from MSSQL but when i reload the list it flickers.
This list is a TableLayoutPanel with dynamic created pictureboxes and labels.
My question is:
How can i change my image inside a dynamic picturebox when u reload my contacts instead of reloading the entire list.
My code to create the table:
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
Image of my contactlist