Je crée une liste de contacts avec VB.NET avec des images d'état. Je charge cette liste depuis MSSQL mais quand je recharge la liste, elle scintille.Modifier l'image à partir d'une image dynamique multiple
Cette liste est un TableLayoutPanel avec des vues dynamiques et des étiquettes créées.
Ma question est:
Comment puis-je changer mon image à l'intérieur d'un picturebox dynamique lorsque u rechargent mes contacts au lieu de recharger la liste complète.
Mon code pour créer la 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 de mon contactlist
Intéressant. Je me souviens avoir suggéré un contrôle de l'utilisateur lorsque vous avez posté il y a un peu de temps. Si vous avez un contrôle utilisateur, vous pouvez gérer ce genre de choses plus facilement ... Ensuite, vous pouvez écrire des méthodes pour gérer n'importe lequel d'entre eux ... Cela signifie que vous devez créer un contrôle utilisateur qui hébergerait tout ce qui concerne cette personne ... pourquoi votre code ci-dessus est long et demande des ennuis. Tout ce qui précède pourrait être réduit de moitié et plus. – Codexer
Voici mon commentaire si vous avez oublié. http://stackoverflow.com/questions/35722326/chat-contact-list-vb-net-and-mssql – Codexer
Je suis d'accord avec @Codexer, et je ne suis pas friand de UserControls à la place des contrôles personnalisés. En l'état, votre formulaire est juste un groupe de contrôles indépendants montrant des informations connexes. – Plutonix