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

C++/CLI Discussion :

ajout de"fonction" dans dictionary


Sujet :

C++/CLI

  1. #1
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut ajout de"fonction" dans dictionary
    Bonsoir ,Je suis novice en la matière et
    suite a mon dictionary de code je voudrai ajouter par exemple un message dans un textBox ou l'affichage d'une pictureBox.
    dans le codage ci dessous le mot exemple s'affiche dans la texBox3 et y reste
    ce qui est normal mais je voudrai changer en fonction de la saisi TexBox1 (add) .Merci pour votre aide .

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    {
        String^ b;
        Dictionary< String^, String^ > ^ dict;
        dict = gcnew Dictionary< String^, String^>();
        dict->Add(L"C004",L"message 1"),(b = "exemple 1");
        dict->Add(L"C005",L"message 2"),(b = "exemple 2");
        dict->Add(L"C006",L"message 3"),(b = "exemple 2");
        dict->Add(L"C007",L"message 3");
        String^ a = textBox1->Text;		 
        String^ Result;
        if(dict->ContainsKey(a)) 
        {
            textBox2->Text = dict[a];
            textBox3->Text = b;
        }
        else 
        {
            textBox2->Text = L"Code Inconnu";
        }
    }

  2. #2
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    J'ai du mal à comprendre ce que tu cherches à faire exactement.
    Peux-tu préciser ?

    Note: Ce n'est pas du C++ normal, mais du C++/CLI et c'est horriblement indenté.
    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.

  3. #3
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    ok je vais essayé d'etre plus clair ,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    dict->Add(L"C004",L"message 1"),(b = "exemple 1");// ici on vas afficher suite dict dans textBox 2: message1  mais je voudrai pouvoir ajouter sois du texte dans une autre textBox3 soit afficher un pictureBox ou les 2.
     
    dict->Add(L"C005",L"message 2");// seul le dict sera affiché dans la texBox2 et rien dans la TextBox3
    "c'est horriblement indenté" peux-tu etre plus clair stp , merci encore pour ton aide .
    @+

  4. #4
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    dict->Add(L"C004",L"message 1"),(b = "exemple 1");
    Tu sais, ça, c'est deux instructions différentes, séparées par un point-virgule. C'est complètement équivalent à cela:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    dict->Add(L"C004",L"message 1");
    b = "exemple 1";
    Si tu veux mettre deux chaînes dans ton dictionnaire, tu dois utiliser un dictionnaire de structures comprenant deux chaînes.
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    public ref class TwoStrings {
    public:
    	String^ first;
    	String^ second;
    };
     
    //...
    		Dictionary< String^, TwoStrings^ > ^ dict;
    Ou encore un dictionnaire de KeyValuePair< String^, String^ >.

    Ou si tu veux, comme le titre l'indique, mettre des fonctions dans ton dictionnaire, il te faut utiliser un dictionnaire de delegates.

    "c'est horriblement indenté" peux-tu etre plus clair stp , merci encore pour ton aide .
    Je disais juste que l'indentation du code que tu as posté est horrible.
    Voici le même code avec l'indentation corrigée:
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    		String^ b;
    		Dictionary< String^, String^ > ^ dict;
    		dict = gcnew Dictionary< String^, String^>();
    		dict->Add(L"C004",L"message 1"), (b = "exemple 1");
    		dict->Add(L"C005",L"message 2"), (b = "exemple 2");
    		dict->Add(L"C006",L"message 3"), (b = "exemple 2");
    		dict->Add(L"C007",L"message 3");
    		String^ a = textBox1->Text;		 
    		String^ Result;
    		if(dict->ContainsKey(a)) 
    		{
    			textBox2->Text = dict[a];
    			textBox3->Text = b;
    		}
    		else 
    			{textBox2->Text = L"Code Inconnu";}
    	}		 
    	};
    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.

  5. #5
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    Pour les 2chaines j'ai essayé mais n'y suis pas arrivé car je ne comprend pas tres bien le fonctionnement ,en codant avec ton exemple j'ai les erreurs :
    error C3156: : vous ne pouvez pas avoir de définition locale d'un type managé
    error C3923: : les définitions de classes, de structures ou d'unions locales ne sont pas autorisées dans une fonction membre d'une classe managée
    error C2143: erreur de syntaxe : absence de ';' avant '{'

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    #pragma endregion
    	private: System::Void button1_Click(System::Object^
    sender,System::EventArgs^  e) 
            {
            public ref class TwoStrings 
           {
            public:
    	String^ first;
    	String^ second;
            }
    	{
             Dictionary< String^, TwoStrings^ > ^ dict;
    	}
    	}
    	};
    }
    et pour utiliser un dictionnaire de delegates, quel en est le principe ?

  6. #6
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Ah, ben évidemment il ne faut pas mettre la définition de classe dans une fonction!
    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.

  7. #7
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut

    ne comprenant pas ce code "TwoStrings^" je n'arrive pas afaire la suite et j'ai toujours l'erreur :error C3379: 'dictionnaire2::Form1::TwoStrings' : une classe imbriquée ne peut pas avoir de spécificateur d'accès à l'assembly comme partie de sa déclaration.
    ou alors je met mal ma definition de classe , j'ai fais plusieurs essais dont voici le dernier :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
     
    #pragma once
    #include <iostream>
    #include <string>
     
    namespace dictionnaire2 {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
        using namespace System::Collections::Generic;
     
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    		}
    	protected:
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
     
    	private:
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(74, 97);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(86, 29);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(66, 40);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(103, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(23, 144);
    			this->textBox2->Multiline = true;
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(220, 42);
    			this->textBox2->TabIndex = 2;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(31, 204);
    			this->textBox3->Multiline = true;
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(212, 47);
    			this->textBox3->TabIndex = 3;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		    }
                    public ref class TwoStrings {
                    public:
    	        String^ first;
    	        String^ second;
    };
    #pragma endregion
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    		     Dictionary< String^, TwoStrings^ > ^ dict;
    			 }
    	};
    }
    Tu parlais d' un dictionnaire de delegates peut tu me poster un exemple c'est peut etre plus simple Non ?.

    Comment fais tu pour garder la mise en forme départ ? dès que je copie/colle
    (visual--> post) le code tout est décalé !!?

  8. #8
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Essaie en déclarant la classe TwoStrings hors de la classe Form1.

    Et pour l'indentation, le problème vient du fait que les tabulations se retrouvent mélangées à des espaces.

    Pour ça, deux étapes:
    Assure-toi que la touche TAB ajoute bien une tabulation et non des espaces (je ne sais plus comment on règle si ce n'est pas le cas).
    Utilise l'option du menu Edition -> Avancé -> Voir les espaces (enfin, un nom du style, je l'ai en Anglais moi), et corrige ton document pour n'avoir plus que des tabs en début de ligne.

    Je l'ai fait sur le code que tu as posté, voici le résultat:
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    #pragma once
    #include <iostream>
    #include <string>
     
    namespace dictionnaire2 {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Collections::Generic;
     
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    		}
    	protected:
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
     
    	private:
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(74, 97);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(86, 29);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(66, 40);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(103, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(23, 144);
    			this->textBox2->Multiline = true;
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(220, 42);
    			this->textBox2->TabIndex = 2;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(31, 204);
    			this->textBox3->Multiline = true;
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(212, 47);
    			this->textBox3->TabIndex = 3;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    		public ref class TwoStrings {
    		public:
    			String^ first;
    			String^ second;
    		};
    #pragma endregion
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    			Dictionary< String^, TwoStrings^ > ^ dict;
    		}
    	};
    }
    Et donc, je t'ai conseillé de sortir la classe TwoStrings de la classe Form1.
    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.

  9. #9
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    Et donc, je t'ai conseillé de sortir la classe TwoStrings de la classe Form1.
    çà je sais pas faire , j'ai essayé de déclarer dans ressource.h mais que des erreurs
    par ailleur si tu m'expliquer ce "TwoStrings " je pourrai faire d'avantage d'essais avant de poster .
    Car là je n'arrive pas a comprendre son fonctionnement , j'ai regardé dans les fac et tuto mais sans succès car c'est une évolution de dictionary.

  10. #10
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Non, dans le même .h.
    Juste hors de la classe...
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    #pragma once
    #include <iostream>
    #include <string>
     
    namespace dictionnaire2 {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Collections::Generic;
     
    	public ref class TwoStrings {
    	public:
    		String^ first;
    		String^ second;
    	};
     
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    		}
    	protected:
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
     
    	private:
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(74, 97);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(86, 29);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(66, 40);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(103, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(23, 144);
    			this->textBox2->Multiline = true;
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(220, 42);
    			this->textBox2->TabIndex = 2;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(31, 204);
    			this->textBox3->Multiline = true;
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(212, 47);
    			this->textBox3->TabIndex = 3;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    			Dictionary< String^, TwoStrings^ > ^ dict;
    		}
    	};
    }
    Quant à la classe TwoStrings, ce n'est rien de plus que ce que c'est: Une classe avec deux strings dedans. Comme ça, pour chaque chaîne possible, on peut stocker deux chaînes...
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    TwoStrings ^twoStrs = gcnew TwoStrings;
    twoStrs->first = L"message 1";
    twoStrs->second = L"exemple 1";
    dict->Add(L"C004", twoStrs);
    //etc.
    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.

  11. #11
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    j'ai codé et voici les erreurs remontées :
    error C2065: 'first' : identificateur non déclaré
    error C2065: 'second' : identificateur non déclaré
    Dans le code (qui ne fonctionne pas )j'ai ajouté mes explications , je me trompe c sur mais pourquoi c ce que j'aimerai comprendre .
    Je ne te demande pas de me coder la fonction mais de m'aider a comprendre car certes quand ça fonctionne c bien mais comprendre c mieux .
    Mon visual est aussi en Anglais je n'ai pas trouver la fonction dont tu disais mais c pas grave il y a pire !! :)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    	private: System::Void button1_Click(System::Object^  sender,
    System::EventArgs^  e) {
    	Dictionary< String^, TwoStrings^ > ^ dict;
            TwoStrings ^twoStrs = gcnew TwoStrings;
            twoStrs->first = L"message 1";// j'assigne "message 1" a first
            twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
            dict->Add(L"C004", twoStrs);// a la Tkey C004 j'ai les valeurs first et second
     
    	 String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
     
              if(dict->ContainsKey(a)) // si dans  dictionary j'ai la tkey == a 
    	  {
    	  textBox2->Text = first;  // j'affiche la Tvalue first
               textBox3->Text = second; // j'affiche la Tvalue second
    	   }  
               else       //si non
    	   { 
    	   textBox2->Text = L"erreur code";  //j'affiche erreur code dans la textBox 2
    	    } 
     
    	    }
    	};
    J'ai aussi essayé çà :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    			 Dictionary< String^, TwoStrings^ > ^ dict;
                 TwoStrings ^twoStrs = gcnew TwoStrings;
                 twoStrs->first = L"message 1";// j'assigne "message 1" a first
                 twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
                 dict->Add(L"C004",  twoStrs );// a la Tkey C004 j'ai les valeurs first et second
     
    	         String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
     
                     if(dict->ContainsKey(a)) // si dans  dictionary j'ai la tkey == a 
    	         {
    	         textBox2->Text = twoStrs->first;// j'affiche la Tvalue first
                     textBox3->Text = twoStrs->second; // j'affiche la Tvalue second
    	         }  
                     else
    	         { 
    	         textBox2->Text = L"erreur code"; 
    	         }
    et voici l'erreur
    Additional information: La référence d'objet n'est pas définie à une instance d'un objet.

  12. #12
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    Pour les tabulations voici le lien :
    Tools/options/Text Editors/All Langages/Tabs et cocher :block

  13. #13
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Pour ton erreur: Normal, dict n'est pas encore créé.

    lolo81 : Mais moi, je parlais de Edit -> Advanced -> View Whitespace.
    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.

  14. #14
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    Comme tu t'en doute j'ai pas trouvé
    voila ce que j'ai mis :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    	     Dictionary< String^, TwoStrings^ > ^ dict;
                 TwoStrings ^twoStrs = gcnew TwoStrings;
                 twoStrs->first = L"message 1";// j'assigne "message 1" a first
                 twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
                 dict->Add(L"C004",L"message1",L"exemple2");
    	     String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
                 String^ Result = "";
                 if(dict->ContainsKey(a)) // si dans  dictionary j'ai la tkey == a 
    	         {
    	         textBox2->Text = twoStrs->first;// j'affiche la Tvalue first
                     textBox3->Text = twoStrs->second; // j'affiche la Tvalue second
    	         }  
                     else
    	         { 
    	         textBox2->Text = L"erreur code"; 
    	         }									    
     
    			 }
    	};
    error C2660: 'System::Collections::Generic:ictionary<TKey,TValue>::Add' : la fonction ne prend pas 3 arguments
    Autrement il ne me dis que les valeur first et second ne sont pas déclarés !! ?

  15. #15
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Étudie ces morceaux de code et pose des questions si tu ne comprends pas.
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    //<Cette partie du code devrait être dans le constructeur de ta classe>
    	//<Cette déclaration devrait être dans la classe, mais hors de toute fonction>
    		Dictionary< String^, TwoStrings^ > ^ dict;
    	//</Cette déclaration devrait être dans la classe, mais hors de toute fonction>
     
    	//Il ne suffit pas de déclarer, le dictionnaire, il faut aussi le créér
    	//On le crée ici:
    	dict = gcnew Dictionary< String^, TwoStrings^ >;
     
    	//Ici, on y ajoute un couple (code, deux chaînes)
    	TwoStrings ^twoStrs = gcnew TwoStrings;
    	twoStrs->first = L"message 1";// j'assigne "message 1" a first
    	twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
    	dict->Add(L"C004", twoStrs);
     
    	//etc.
    //</Cette partie du code devrait être dans le constructeur de ta classe>
     
    //<Cette partie du code est dans ta fonction>
    	String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
    	String^ Result = "";
    	//Ici, on utilise TryGetValue() plutôt que ContainsKey
    	TwoStrings ^twoStrs;
    	if(dict->TryGetValue(a, twoStrs)) // si dans  dictionary j'ai la tkey == a 
    	{
    		textBox2->Text = twoStrs->first;// j'affiche la Tvalue first
    		textBox3->Text = twoStrs->second; // j'affiche la Tvalue second
    	}
    	else
    	{
    		textBox2->Text = L"erreur code"; 
    	}
    //</Cette partie du code est dans ta fonction>
    	}
    };
    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.

  16. #16
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    J'ai appliqué ces modifications au code des messages précédents.
    Peux-tu me dire si ça compile chez toi?
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    #pragma once
    #include <iostream>
    #include <string>
     
    namespace dictionnaire2 {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Collections::Generic;
     
    	public ref class TwoStrings {
    	public:
    		String^ first;
    		String^ second;
    	};
     
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
     
    			//Il ne suffit pas de déclarer le dictionnaire, il faut aussi le créér
    			//On le crée ici:
    			dict = gcnew Dictionary< String^, TwoStrings^ >;
     
    			//Ici, on y ajoute un couple (code, deux chaînes)
    			TwoStrings ^twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 1";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
    			dict->Add(L"C004", twoStrs);
     
    			//etc.
    		}
    	protected:
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private:
    		Dictionary< String^, TwoStrings^ > ^ dict;
     
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
     
    	private:
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(74, 97);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(86, 29);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(66, 40);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(103, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(23, 144);
    			this->textBox2->Multiline = true;
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(220, 42);
    			this->textBox2->TabIndex = 2;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(31, 204);
    			this->textBox3->Multiline = true;
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(212, 47);
    			this->textBox3->TabIndex = 3;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion
    	private:
    		System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e)
    		{
    			String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
    			//Ici, on utilise TryGetValue() plutôt que ContainsKey
    			TwoStrings ^twoStrs;
    			if(dict->TryGetValue(a, twoStrs)) // si dans  dictionary j'ai la tkey == a 
    			{
    				textBox2->Text = twoStrs->first;// j'affiche la Tvalue first
    				textBox3->Text = twoStrs->second; // j'affiche la Tvalue second
    			}
    			else
    			{
    				textBox2->Text = L"erreur code"; 
    			}
    		}
    	};
    }
    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.

  17. #17
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    Oui ça compile avec un message :Warning 1 The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again.
    J'ai fais copier/coller c'est peut etre normal ?!!
    Le dico ne fonctionne pas --> il garde la derniere valeur de chaine (message 3 et "" )
    En revanche (ce qui est peut être mieux) le "message1" et l'"exemple 1" s'affiche directement sans cliquer sur valider .
    //Il ne suffit pas de déclarer, le dictionnaire, il faut aussi le créer
    //On le crée ici:
    Au debut (avec une seule chaîne et 700) je l'avais declaré sous commande de Button1 qui fonctionné mais là ça va pas bugué avec pres de 1400 codes dont env 300 chaines ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    			//Ici, on y ajoute un couple (code, deux chaînes)
    			TwoStrings ^twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 1";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
    			dict->Add(L"C004", twoStrs);
     
     
    			twoStrs->first = L"message 2";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 2";
    			dict->Add(L"C005", twoStrs);
     
     
    			twoStrs->first = L"message 3";// j'assigne "message 1" a first
    			twoStrs->second = L"";
    			dict->Add(L"C006", twoStrs);

  18. #18
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    OK, je vois le problème.

    Pour ton erreur: Essaie en déplaçant la classe TwoStrings dans un nouveau fichier d'en-tête (avec le même namespace), et fais un #include de ce fichier d'en-tête dans Form1.h


    Pour ton problème sur les chaînes: Il faut refaire un gcnew TwoStrings à chaque fois:
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    			//Ici, on y ajoute un couple (code, deux chaînes)
    			TwoStrings ^twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 1";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
    			dict->Add(L"C004", twoStrs);
    			
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 2";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 2";
    			dict->Add(L"C005", twoStrs);
    			
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 3";// j'assigne "message 1" a first
    			twoStrs->second = L"";
    			dict->Add(L"C006", twoStrs);
    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.

  19. #19
    Membre très actif
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    254
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 254
    Par défaut
    j'ai fais le 2eme fichier mais il me le trouver pas pourtant j'ai mis#include "fichier2" dans Form1 et mis la Classe dans fichier2 avec comme en tête namespace dico2 !!?
    J'ai tous recommencé et là ça marche mais imposible de modifier la Form1[design]
    Question : dans le cas ou j'ajoute une 3eme string je fais pareil(TwoStrings) ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
     
    #pragma once
    #pragma once
    #include <iostream>
    #include <string>
     
    namespace dico2 {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Collections::Generic;
     
    	public ref class TwoStrings {
    	public:
    		String^ first;
    		String^ second;
    	};
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//Il ne suffit pas de déclarer le dictionnaire, il faut aussi le créér
    			//On le crée ici:
    			dict = gcnew Dictionary< String^, TwoStrings^ >;
    			//Ici, on y ajoute un couple (code, deux chaînes)
    			TwoStrings ^twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 1";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
    			dict->Add(L"C004", twoStrs);
     
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 2";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 2";
    			dict->Add(L"C005", twoStrs);
     
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 3";// j'assigne "message 1" a first
    			dict->Add(L"C006", twoStrs);
     
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 4";// j'assigne "message 1" a first
    			dict->Add(L"C007", twoStrs);
    		}
     
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    			private:
    		Dictionary< String^, TwoStrings^ > ^ dict;
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
     
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(100, 88);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(75, 23);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(88, 43);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(100, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(88, 136);
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(100, 20);
    			this->textBox2->TabIndex = 2;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(88, 199);
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(100, 20);
    			this->textBox3->TabIndex = 3;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    			 			String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
    			//Ici, on utilise TryGetValue() plutôt que ContainsKey
    			TwoStrings ^twoStrs;
    			if(dict->TryGetValue(a, twoStrs)) // si dans  dictionary j'ai la tkey == a 
    			{
    				textBox2->Text = twoStrs->first;// j'affiche la Tvalue first
    				textBox3->Text = twoStrs->second; // j'affiche la Tvalue second
    			}
    			else
    			{
    				textBox2->Text = L"erreur code";
    				textBox3->Text = "";
    			}
    			}
    	};
    }

  20. #20
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    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 395
    Par défaut
    Je parlais de séparer comme ceci:
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    //TwoStrings.h
     
    namespace dico2 {
    	using namespace System;
     
    	public ref class TwoStrings {
    	public:
    		String^ first;
    		String^ second;
    	};
    }
    Code C++/CLI : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    // Form1.h
    #pragma once
    #include <iostream>
    #include <string>
     
    #include "TwoStrings.h"
     
    namespace dico2 {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Collections::Generic;
     
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//Il ne suffit pas de déclarer le dictionnaire, il faut aussi le créér
    			//On le crée ici:
    			dict = gcnew Dictionary< String^, TwoStrings^ >;
    			//Ici, on y ajoute un couple (code, deux chaînes)
    			TwoStrings ^twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 1";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 1";// j'assigne "exemple 1" a second
    			dict->Add(L"C004", twoStrs);
     
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 2";// j'assigne "message 1" a first
    			twoStrs->second = L"exemple 2";
    			dict->Add(L"C005", twoStrs);
     
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 3";// j'assigne "message 1" a first
    			dict->Add(L"C006", twoStrs);
     
    			twoStrs = gcnew TwoStrings;
    			twoStrs->first = L"message 4";// j'assigne "message 1" a first
    			dict->Add(L"C007", twoStrs);
    		}
     
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private:
    		Dictionary< String^, TwoStrings^ > ^ dict;
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::TextBox^  textBox3;
     
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(100, 88);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(75, 23);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(88, 43);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(100, 20);
    			this->textBox1->TabIndex = 1;
    			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(88, 136);
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(100, 20);
    			this->textBox2->TabIndex = 2;
    			// 
    			// textBox3
    			// 
    			this->textBox3->Location = System::Drawing::Point(88, 199);
    			this->textBox3->Name = L"textBox3";
    			this->textBox3->Size = System::Drawing::Size(100, 20);
    			this->textBox3->TabIndex = 3;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->textBox3);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion
    	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    			 			String^ a = textBox1->Text; // je declare 'a' ayant comme valeur la textbox 
    			//Ici, on utilise TryGetValue() plutôt que ContainsKey
    			TwoStrings ^twoStrs;
    			if(dict->TryGetValue(a, twoStrs)) // si dans  dictionary j'ai la tkey == a 
    			{
    				textBox2->Text = twoStrs->first;// j'affiche la Tvalue first
    				textBox3->Text = twoStrs->second; // j'affiche la Tvalue second
    			}
    			else
    			{
    				textBox2->Text = L"erreur code";
    				textBox3->Text = "";
    			}
    			}
    	};
    }
    Et si tu veux mettre trois chaînes, tu peux toujours te faire une classe ThreeStrings...
    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.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [Fonction] Quote et guillemet dans un textarea
    Par ddelec24 dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 11/03/2007, 15h51

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