Communication entre un thread et des composants WinForm
Bonjour,
J'ai un petit souci avec la création d'un thread qui a pour rôle l'implémentation de miniatures dans un TableLayoutPanel sachant que chaque miniature est un PictureBox.
Je voudrais savoir comment je peux accéder à ces composants via mon thread.
Voici le code du thread et en rouge les lignes en erreur :
Création du thread :
Code:
1 2 3 4
|
this.Mosaique =
new Thread(new ThreadStart(this.affiche_mosa));
this.Mosaique.Start(); |
contenu du thread :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
private void affiche_mosa()
{
// on affiche la mosaique
foreach (string fichier in Directory.GetFiles(file_dest))
{
// on ajoute la photo dans la mosaique
PictureBox img = new PictureBox();
img.Name = "vignette " + posit;
img.Size = new System.Drawing.Size(85, 85);
img.Image = new Bitmap(fichier);
img.SizeMode = PictureBoxSizeMode.Zoom;
this.Controls.Add(img);
this.mosa.Controls.Add(img, i, j);
if (i == 4)
{
i = 0;
j = j + 1;
}
i = i + 1;
posit = posit + 1;
}
} |
Merci.