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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  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 ...)

+ 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