IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

VC++ .NET Discussion :

String to Label


Sujet :

VC++ .NET

  1. #1
    Membre confirm�
    Inscrit en
    Juillet 2007
    Messages
    124
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Par d�faut String to Label
    Bonjours je veux convertir un string en Label

    je veux faire ceci parce que je dois faire la m�me chose 216 fois

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    e->Graphics->DrawString(label3->Text,label3->Font,Brushes::Black,label3->Location.X,label3->Location.Y);
    			e->Graphics->DrawString(label4->Text,label4->Font,Brushes::Black,label4->Location.X,label4->Location.Y);
    			e->Graphics->DrawString(label5->Text,label5->Font,Brushes::Black,label5->Location.X,label5->Location.Y);
    			e->Graphics->DrawString(label6->Text,label6->Font,Brushes::Black,label6->Location.X,label6->Location.Y);
    			e->Graphics->DrawString(label7->Text,label7->Font,Brushes::Black,label7->Location.X,label7->Location.Y);
    			e->Graphics->DrawString(label8->Text,label8->Font,Brushes::Black,label8->Location.X,label8->Location.Y);
    			e->Graphics->DrawString(label9->Text,label9->Font,Brushes::Black,label9->Location.X,label9->Location.Y);
    			e->Graphics->DrawString(label10->Text,label10->Font,Brushes::Black,label10->Location.X,label10->Location.Y);
    			e->Graphics->DrawString(label11->Text,label11->Font,Brushes::Black,label11->Location.X,label11->Location.Y);
    j'avais pens� faire ca comme ca mais ca fonctionne pas

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    for (int i=0 ; i<216 ; i++) 
    			{
    			   String ^NomLabel = "label"+i;
    			   Label^ Lb = safe_cast< Label^ >(NomLabel);
    			   e->Graphics->DrawString(Lb->Text,Lb->Font,Brushes::Black,Lb->Location.X,Lb->Location.Y);
    			}
    Est-ce quelqu'un pourrais m'aider S.V.P Merci

    TrollTop c++.net

  2. #2
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    ce n'est pas du tout comme ca qu'il faut faire
    si tu veux cr�er un label dynamiquement, il faudrait plutot faire un truc du genre :

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
     
    Label ^monLabel = gcnew Label();
    monLabel->Text = "ma chaine";
    // ajouter le label à la form (ou à un panel)
    this->Controls->Add(monLabel); // this étant la form

  3. #3
    Membre confirm�
    Inscrit en
    Juillet 2007
    Messages
    124
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Par d�faut
    ca peut pas fonctionner ca c'est pas ca que je veux faire

    je veux que monLabel = label0 , label1, label2 , label3, label4 ect...jusqu'� label 216 avec tout ce qu'ils contiennent le Text , Font , Location tout quoi une copie conforme. un apr�s l'autre dans un for

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    e->Graphics->DrawString(label1->Text,label1->Font,Brushes::Black,label1->Location.X+200,label1->Location.Y);
    e->Graphics->DrawString(label2->Text,label2->Font,Brushes::Black,label2->Location.X+300,label2->Location.Y);
    e->Graphics->DrawString(label3->Text,label3->Font,Brushes::Black,label3->Location.X,label3->Location.Y);
    e->Graphics->DrawString(label4->Text,label4->Font,Brushes::Black,label4->Location.X,label4->Location.Y);
    e->Graphics->DrawString(label5->Text,label5->Font,Brushes::Black,label5->Location.X,label5->Location.Y);
    e->Graphics->DrawString(label6->Text,label6->Font,Brushes::Black,label6->Location.X,label6->Location.Y);
    e->Graphics->DrawString(label7->Text,label7->Font,Brushes::Black,label7->Location.X,label7->Location.Y);
    e->Graphics->DrawString(label8->Text,label8->Font,Brushes::Black,label8->Location.X,label8->Location.Y);
    e->Graphics->DrawString(label9->Text,label9->Font,Brushes::Black,label9->Location.X,label9->Location.Y);
    e->Graphics->DrawString(label10->Text,label10->Font,Brushes::Black,label10->Location.X,label10->Location.Y);
    e->Graphics->DrawString(label11->Text,label11->Font,Brushes::Black,label11->Location.X,label11->Location.Y);
    j'esp�re que tu comprend

    TrollTop c++.net

  4. #4
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    non, j'ai rien compris

  5. #5
    Membre confirm�
    Inscrit en
    Juillet 2007
    Messages
    124
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Par d�faut
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    e->Graphics->DrawString(label1->Text,label1->Font,Brushes::Black,label1->Location.X,label1->Location.Y);
    e->Graphics->DrawString(label2->Text,label2->Font,Brushes::Black,label2->Location.X,label2->Location.Y);
    e->Graphics->DrawString(label3->Text,label3->Font,Brushes::Black,label3->Location.X,label3->Location.Y);
    e->Graphics->DrawString(label4->Text,label4->Font,Brushes::Black,label4->Location.X,label4->Location.Y);
    e->Graphics->DrawString(label5->Text,label5->Font,Brushes::Black,label5->Location.X,label5->Location.Y);
    e->Graphics->DrawString(label6->Text,label6->Font,Brushes::Black,label6->Location.X,label6->Location.Y);
    e->Graphics->DrawString(label7->Text,label7->Font,Brushes::Black,label7->Location.X,label7->Location.Y);
    e->Graphics->DrawString(label8->Text,label8->Font,Brushes::Black,label8->Location.X,label8->Location.Y);
    e->Graphics->DrawString(label9->Text,label9->Font,Brushes::Black,label9->Location.X,label9->Location.Y);
    e->Graphics->DrawString(label10->Text,label10->Font,Brushes::Black,label10->Location.X,label10->Location.Y);
    e->Graphics->DrawString(label11->Text,label11->Font,Brushes::Black,label11->Location.X,label11->Location.Y);
    Je veux pas � avoir � faire ces lignes 216 fois

    je veux le faire dans un for i

    for (int i=0 ; i<216 ; i++)
    {
    e->Graphics->DrawString(label+i->Text,label+i->Font,Brushes::Black,label+i->Location.X,label+i->Location.Y);
    }

    je veux le faire une fois . comme ca je vais avoir 3 lignes de programme au lieu de 216 lignes

    si tu comprend pas . Je sais pas comment te l'expliquer autrement.

    TrollTop c++.net

  6. #6
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    ca peut pas marcher comme ca ...

    je vois deux possibilit�s assez simple � mettre en oeuvre pour trouver ton textBox.

    Avec
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    this->Controls->Find(nomDuTextBox, true);
    sachant que ca va te renvoyer un tableau de textBox contenant 1 seul textbox, donc il faudra acceder � l'�l�ment 0

    soit en bouclant sur tous les controles et en testant si le controle est de type textBox, dans le meme genre que dans la faq C++/CLI http://dotnet.developpez.com/faq/cpp...ypeidentity#is

    (et au pire, si jamais tu as des textbox que tu ne veux pas traiter, tu pourras faire un filtre sur le nom ...)

  7. #7
    Membre confirm�
    Inscrit en
    Juillet 2007
    Messages
    124
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Par d�faut
    t� sur que tu parle de la m�me affaire que moi Parce que moi c'est des Label et non des TextBox . pis je veux pas les trouver. Je sais que je veux les labels de 0 � 215 .

    TrollTop c++.net

  8. #8
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    au temps pour moi, mais c'est pareil, le principe est le meme pour un textbox ou pour un label

    il ne s'agit de "les retrouver" que pour pouvoir agir dessus.

    tu ne peux pas utiliser une variable dans un nom de variable

  9. #9
    Membre confirm�
    Inscrit en
    Juillet 2007
    Messages
    124
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Par d�faut
    Si je Comprend bien . Je fais �a comme �a

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    array<Label ^> ^ MonLabel = gcnew array<Label ^>(1);
     
    		for (int i=0 ; i<216 ; i++) 
    			{
    			   String ^NomLabel = "label"+i;
    			   MonLabel = this->Controls->Find(NomLabel, true);
    			   e->Graphics->DrawString(MonLabel[0]->Text,MonLabel[0]->Font,Brushes::Black,MonLabel[0]->Location.X,MonLabel[0]->Location.Y);
    			}
    ca me fait 2 erreurs les voici

    error C2440: '=' : impossible de convertir de 'cli::array<Type,dimension> ^' en 'cli::array<Type,dimension> ^'
    1> with
    1> [
    1> Type=System::Windows::Forms::Control ^,
    1> dimension=1
    1> ]
    1> and
    1> [
    1> Type=System::Windows::Forms::Label ^,
    1> dimension=1
    1> ]

  10. #10
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    for (int i = 0 ; i < 256 ; i++)
    {
     array<Control ^> ^labelATrouver = Controls->Find(String::Format("label{0}", i), true);
     if (labelATrouver != nullptr && labelATrouver->Length > 0)
     {
    	 // faire qqchose avec le label 
    	 labelATrouver[0]->Text = .......;
     }
    }

  11. #11
    Membre confirm�
    Inscrit en
    Juillet 2007
    Messages
    124
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 124
    Par d�faut
    Merci Beaucoup , Tu est un As du C++.Net

    TrollTop c++.net

  12. #12
    Expert �minent
    Avatar de M�dinoc
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 397
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 41
    Localisation : France

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 397
    Par d�faut
    Ne dis pas C++.Net, �a sonne trop Managed C++...
    L�, tu bosses en C++/CLI...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parl� avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. Affichage d'un melange d'entier et string dans un label
    Par zodiak66 dans le forum D�buter
    R�ponses: 4
    Dernier message: 03/06/2011, 22h28
  2. Comparaison de label et de string
    Par SonnyFab dans le forum ASP.NET
    R�ponses: 6
    Dernier message: 22/06/2010, 14h59
  3. Adresser un Label � partir d'une chaine string
    Par Fenixecu dans le forum Windows Forms
    R�ponses: 4
    Dernier message: 23/02/2009, 09h29
  4. R�ponses: 1
    Dernier message: 13/09/2007, 11h56
  5. Utilisation de string et dates comme labels d'axes
    Par _moebius_ dans le forum MATLAB
    R�ponses: 3
    Dernier message: 15/06/2007, 11h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo