Label.DefaultBackColor = Color.Transparent
Résolu
arion320
Messages postés
219
Date d'inscription
Statut
Membre
Dernière intervention
-
arion320 Messages postés 219 Date d'inscription Statut Membre Dernière intervention -
arion320 Messages postés 219 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je pensais avoir trouvé une solution mais finalement mon problème persiste. Alors voilà ; J'essaye de définir globalement une couleurs par défaut de mes label car jusqu'à maintenant j'ai fait manuellement :
Tout cela fait que le code est très lourd et donc le logiciel est non performant.
Je chercher un moyen de définir tout les labels avec un BackColor et un ForeColor par défault pour m'éviter décrire tout cela.
Second problème, vous me direz sûrement « Définit-les directement via ta form » mais le problème c'est que toutes les couleurs disparaissent (Sûrement à cause d'un surplus de composants). Donc, dès que je compile le tout et que je l'exécute, les problèmes persistes.
Auriez-vous une solution ?
Merci d'avance.
--
Cordialement, Arion320
Je pensais avoir trouvé une solution mais finalement mon problème persiste. Alors voilà ; J'essaye de définir globalement une couleurs par défaut de mes label car jusqu'à maintenant j'ai fait manuellement :
Settings.Panel3.BackColor = Color.DodgerBlue
Settings.Panel2.BackColor = Color.DodgerBlue
Settings.Panel7.BackColor = Color.DodgerBlue
Settings.Panel12.BackColor = Color.DodgerBlue
Settings.Panel13.BackColor = Color.DodgerBlue
Settings.PanelInformations.BackColor = Color.White
Settings.PanelDesPanels.BackColor = Color.Transparent
Settings.TextBox1.BackColor = Color.White
Settings.TextBox1.ForeColor = Color.Black
Settings.Label18.BackColor = Color.Transparent
Settings.PanelDonation.BackColor = Color.Transparent
Settings.Label18.ForeColor = Color.OrangeRed
Settings.PanelLanguage.BackColor = Color.Transparent
Settings.Label1.BackColor = Color.Transparent
Settings.Label2.BackColor = Color.Transparent
Settings.Panel15.BackColor = Color.FromArgb(235, 60, 0)
Settings.Panel17.BackColor = Color.FromArgb(235, 60, 0)
Settings.Panel19.BackColor = Color.FromArgb(235, 60, 0)
Settings.Label6.BackColor = Settings.Panel5.BackColor
Settings.Label7.BackColor = Settings.Panel5.BackColor
Settings.Label17.BackColor = Color.Transparent
Settings.Label17.ForeColor = Color.White
Settings.Label20.BackColor = Color.Transparent
Settings.Label20.ForeColor = Color.White
Settings.Label3.BackColor = Color.Transparent
Settings.GroupBox3.BackColor = Color.Transparent
Settings.Label4.BackColor = Color.Transparent
Settings.PictureBox1.BackColor = Color.Transparent
Settings.PictureBoxEnglishSelection.BackColor = Color.Transparent
Settings.PictureBoxFrenchSelection.BackColor = Color.Transparent
Settings.RadioButton1.BackColor = Color.Transparent
Settings.RadioButton2.BackColor = Color.Transparent
Settings.Label5.BackColor = Color.Transparent
Settings.Label9.BackColor = Settings.Panel5.BackColor
Settings.Panel16.BackColor = Color.FromArgb(64, 64, 64)
Settings.Panel22.BackColor = Color.FromArgb(64, 64, 64)
Settings.Panel21.BackColor = Color.DodgerBlue
Settings.PictureBox4.BackColor = Color.Transparent
Settings.Label16.BackColor = Settings.Panel5.BackColor
Settings.Panel4.BackColor = Color.Transparent
Settings.PictureBox6.BackColor = Color.Transparent
Settings.Label8.BackColor = Color.Transparent
Settings.Label12.BackColor = Color.Transparent
Settings.Label15.BackColor = Color.Transparent
Settings.LinkLabel2.BackColor = Color.Transparent
Settings.Label13.BackColor = Color.Transparent
Settings.PictureBox5.BackColor = Color.Transparent
Settings.LinkLabel3.BackColor = Color.Transparent
Settings.LinkLabel4.BackColor = Color.Transparent
Settings.Label11.BackColor = Color.Transparent
Settings.Label10.BackColor = Color.Transparent
Settings.Label14.BackColor = Color.Transparent
Settings.Label8.ForeColor = Color.White
Settings.Label12.ForeColor = Color.White
Settings.Label1.ForeColor = Color.White
Settings.Label2.ForeColor = Color.White
Settings.Label4.ForeColor = Color.White
Settings.Label5.ForeColor = Color.White
Settings.PanelEmplacements.BackColor = Color.White
Settings.PictureBox9.BackColor = Color.Transparent
Settings.LinkLabel2.ForeColor = Color.White
Settings.LinkLabel4.ForeColor = Color.White
Settings.GroupBox1.BackColor = Color.Transparent
Settings.GroupBox2.BackColor = Color.Transparent
Settings.Label21.BackColor = Color.Transparent
Settings.PevisualisationPredef.BackColor = Color.Transparent
Settings.PrevisualisationPerso.BackColor = Color.Transparent
Settings.LinkLabel3.ForeColor = Color.White
Settings.Panel18.BackColor = Color.White
Settings.Panel20.BackColor = Color.Gainsboro
Settings.Label11.ForeColor = Color.White
Settings.Label10.ForeColor = Color.White
Settings.Label13.ForeColor = Color.White
Settings.Label14.ForeColor = Color.White
Settings.Button1.BackColor = Color.Transparent
Settings.Button9.BackColor = Color.Transparent
Settings.Button6.BackColor = Color.Transparent
Settings.Button7.BackColor = Color.Transparent
Settings.Button5.BackColor = Color.Transparent
Settings.Button14.BackColor = Color.Transparent
Settings.Button8.BackColor = Color.Transparent
Settings.Button2.BackColor = Color.Transparent
Settings.Button15.BackColor = Color.Transparent
Settings.Button13.BackColor = Color.Transparent
Settings.Button4.BackColor = Color.Transparent
Settings.Button1.ForeColor = Color.Black
Settings.Button2.ForeColor = Color.Black
Settings.PictureBox8.BackColor = Color.Transparent
Settings.PictureBox7.BackColor = Color.Transparent
Settings.PictureBox13.BackColor = Color.Transparent
Settings.PictureBox14.BackColor = Color.Transparent
Settings.PictureBox15.BackColor = Color.Transparent
Settings.Label23.BackColor = Color.Transparent
Settings.Label22.BackColor = Color.Transparent
Settings.Label24.BackColor = Color.Transparent
Settings.Label26.BackColor = Color.Transparent
Settings.Label25.BackColor = Color.Transparent
Settings.Label34.BackColor = Color.Transparent
Settings.Label27.BackColor = Color.Transparent
Settings.Label28.BackColor = Color.Transparent
Settings.Label33.BackColor = Color.Transparent
Settings.Label32.BackColor = Color.Transparent
Settings.Label19.BackColor = Settings.Panel5.BackColor
Tout cela fait que le code est très lourd et donc le logiciel est non performant.
Je chercher un moyen de définir tout les labels avec un BackColor et un ForeColor par défault pour m'éviter décrire tout cela.
Second problème, vous me direz sûrement « Définit-les directement via ta form » mais le problème c'est que toutes les couleurs disparaissent (Sûrement à cause d'un surplus de composants). Donc, dès que je compile le tout et que je l'exécute, les problèmes persistes.
Auriez-vous une solution ?
Merci d'avance.
--
Cordialement, Arion320
2 réponses
-
Bonjour
For Each c As Control In Me.Controls Select Case c.GetType() Case GetType(Label) Dim l As Label = TryCast(c, Label) l.BackColor = Color.Yellow l.ForeColor = Color.Red Case 'autre... End Select Next c
Quand j'étais petit, la mer Morte n'était que malade.
George Burns-
Bonsoir Whismeril, je tante de comprendre vôtre code mais je n'arrive pas du tout à me repéré. J'aimerais m'améliorer en tentant de comprendre comment l'avez-vous définit. Je ne connaît les bases de visual basic mais à vrais dire je n'ai jamais utiliser "For Each"
Ni "Select Case" & "GetType"...
Pourriez-vous m'éclairer ? Merci d'avance
-
-
Bonjour
Je ne connaît les bases de visual basic mais à vrais dire je n'ai jamais utiliser "For Each"
c'est très contradictoire comme phrase. Les boucles ça s'apprend plutôt au début...
Le meilleur conseil que je puisse te donner c'est de revoir tes bases, voici un bon cours
https://plasserre.developpez.com/cours/vb-net/
Un boucle For Each est donc une boucle qui itère chaque élément d'une collection dans l'ordre.
Un select case est une sorte d'aiguillage:- choix 1 je fais ça
- choix 2 je fais si
- etc...
GetType permet comme son nom l'indique de retourne le type d'un objet.
Et donc ça permet de différencier quel contrôle aura quel couleur
VB.net est un langage "tout" objet, donc prend en charge l'héritage, ainsi, un Label hérite de Control, et tout et n'importe quoi hérite d'Object.
Donc on itère la collection de contrôles du formulaire, à ce moment là c est considéré comme un Control pour le compilateur, puisqu'il est issu d'une collection de Controls, après avoir vérifié qu'il s'agit bien d'un Label, je le caste en Label pour accéder à toutes ses propriétés et affecter celles qui m'interressent-
Merci beaucoup pour ta réponse,
Je connaît tout ce qui est "Try/Catch/End Try" , "If / Else / ElseIf", etc.. je comprends mieux à quoi sert le "For Each" je pense que je vais tanter de réviser de plus en plus pour pouvoir le contrôler parfaitement.
Merci encore pour toutes tes explications.
Cordialement,
Simon -
-