Bonjour à tous,
dans le but de simplifier mon code je cherche la méthode me permettant d'appliquer une actions à plusieurs objet en même temps sans devoir écrire une ligne de code pour chaque objet.
Actuellement si je veux changer la couleur de police à mes 10 textBox je fais ces 10 lignes:
J'ai pris cet exemple simple mais c'est valable pour d'autres objets, comment faire pour utiliser le chiffre du nom de l'objet (ex Txt1) dans une boucle?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 this.Txt1.ForeColor = System.Drawing.Color.Black; this.Txt2.ForeColor = System.Drawing.Color.Black; this.Txt3.ForeColor = System.Drawing.Color.Black; this.Txt4.ForeColor = System.Drawing.Color.Black; this.Txt5.ForeColor = System.Drawing.Color.Black; this.Txt6.ForeColor = System.Drawing.Color.Black; this.Txt7.ForeColor = System.Drawing.Color.Black; this.Txt8.ForeColor = System.Drawing.Color.Black; this.Txt9.ForeColor = System.Drawing.Color.Black; this.Txt10.ForeColor = System.Drawing.Color.Black;
Merci de votre aide,
bonne journée!!
Partager