Syntaxe ? Color.X

Résolu
bip98 Messages postés 104 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 29 avril 2008 - 19 janv. 2005 à 15:13
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 - 25 janv. 2005 à 14:12
Petite question.. surment très bête..

J'ai une variable..

public string v_color=red

et je voudrais que l'objet color selectionne la couleur "red"..

Normalement on fait comme ça: Color.Red;
Mais je voudrais le faire par rapport à ma variable: Color.v_color;

Mais ça compile pas.. comment faire ? pour la bonne syntaxe.

Salutations

3 réponses

cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
19 janv. 2005 à 15:28
En utilisant la reflexion :

Type colorType = typeof(Color);
PropertyInfo myColorPropInfo = colorType.GetProperty(v_color);
Color myColor = (Color)myColorPropInfo.GetValue(null, new object[]{});

Cocoricoooooooo !!!!
coq
MVP Visual C#
3
bip98 Messages postés 104 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 29 avril 2008 1
25 janv. 2005 à 14:04
Pour ceux qui voudrait utiliser ce code, ne pas oublier :



using System.Reflection;







Merci M.Coq pour le code ! C'est très sympa
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
25 janv. 2005 à 14:12
ah oui j'avais oublier de le préciser lol

de rien :-)

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
Rejoignez-nous