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

Windows Forms Discussion :

Comment modifier le texte des contrôles !?


Sujet :

Windows Forms

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2006
    Messages : 147
    Points : 84
    Points
    84
    Par défaut Comment modifier le texte des contrôles !?
    Bonjour,

    Question simple mais je ne trouve nulle part. J'ai un projet sous Visual C++.
    Ce projet doit être multilingue.
    Comment fait-on pour modifier le texte des contrôles à l'exécution ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    NameSpace::WindowName::ButtonName->text = "..." ?
    NameSpace::WindowName::ButtonName::SetWindowText("...") ?
    ....
    Et quelle type de variable chaîne utiliser ?

    C'est sûrement trivial, ou ça devrait l'être... mais apparemment pas et pour l'instant rien ne compile.

    Venant de Delphi, il me suffisait de faire un simple ButtonName.Caption = '...';

    Merci d'avance.

  2. #2
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    bonjour,

    un projet sous Visual C++ veut surement donc dire un projet c ou c++, hors ces 2 langages non pas de gestion des ihm intégré, donc c'est forcément une lib externe.

    par exemple il y a wxwidget, qt, gtk, win32, etc. donc sans connaitre la technologie, on ne peut pas deviner la syntaxe à adopter pour le changement de texte d'un contrôle.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2006
    Messages : 147
    Points : 84
    Points
    84
    Par défaut
    Tout ce que je sais, c'est que c'est du Windows Form. (Pas MFC donc)

    Cela répond-il à la question ?

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Bonjour,

    c'est pas ça ? http://msdn.microsoft.com/en-us/libr...text.aspx#Y500
    ou ? http://msdn.microsoft.com/en-us/libr...s.textbox.aspx http://msdn.microsoft.com/fr-fr/libr...(v=vs.80).aspx
    J'ai également aperçu cet exemple en JAVA (?)

    Tout ça se ressemble, et un simple myBtn.Text = "my new text"; semble suffire..

    Qu'as-tu testé ? ça compile ? ça crash à l'exécution ? quel résultat as-tu ?
    ne faut-il pas forcer un redraw après une telle opération ?
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2006
    Messages : 147
    Points : 84
    Points
    84
    Par défaut
    En fait, je peux faire ça dans le .h du form :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    String^ txt = gcnew String(result.c_str());
    this->MyButton->Text = txt;
    Ca, ça fonctionne.
    Mais depuis une autre unité impossible car l'accès à Text n'est pas accepté à cause du "private" au niveau de la déclaration de la propriété je suppose...

    Mais je ne peux pas non plus utiliser la méthode SetWindowText.
    Le compilateur me dit dit que SetWindowTextW n'existe pas.

  6. #6
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Comment est déclaré MyButton ?
    Comment essayes-tu d'y accéder ?

    Si Text était private, tu n'y aurais pas accès du tout, ton souci est sûrement un accès à MyButton, et non à Text. Surtout quand msdn indique que Text est "Public property".

    MyClass->MyAwesomeButtonGetter()->Text = "my new awesome text";

    Toujours aucun vrai code ni message d'erreur.....? Mes dons de voyance commencent à s'amenuiser.

    edit : SetWindowText(hWnd, lpStr)
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2006
    Messages : 147
    Points : 84
    Points
    84
    Par défaut
    Voici ce que j'ai essayé par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    WMain::MainForm::CloseButton->text = L"test" ;
    L'erreur de compilation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    error C2227: la partie gauche de '->text' doit pointer vers un type class/struct/union/générique

    Et voici le code :

    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
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
     
    namespace WMain {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
     
    	/// <summary>
    	/// Description résumée de MainForm
    	/// </summary>
    	public ref class MainForm : public System::Windows::Forms::Form
    	{
    	public: static MainForm^ p_mainForm;
    	private: Comparator * comparator;
    	private: WinPref *  myPref;
    	private: Launcher * p_launch;
    	private: HDC		hdc;
    	private: System::Windows::Forms::Label^  DiffEdit;
    	private: System::Windows::Forms::TextBox^  AlertDiff;
    	private: System::Windows::Forms::TextBox^  AlertLum;
     
    	private: System::Windows::Forms::Label^  LumiEdit;
    	public:
    		// Constructeur fenetre principale
    		MainForm(Comparator * comp, WinPref * pref)
    		{
    			InitializeComponent();
    			this->ControlBox = false;
    			comparator = comp;
    			myPref = pref;
    			p_launch = NULL;
    			hdc = GetDC( (HWND) this->Handle.ToInt32() );
    		}
    		//Getter handle de la fenetre
    		HWND getWin()
    		{
    			return (HWND)this->Handle.ToPointer();
    		}
    		//Setter du launcher
    		void setLauncher(Launcher * launch)
    		{
    			p_launch = launch;
    		}
    	protected:
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		~MainForm()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  CloseButton;
    	private: System::Windows::Forms::Button^  StartStopButton;
    	private: System::Windows::Forms::Button^  PreferenceButton;
    	private: System::Windows::Forms::ProgressBar^  DiffProgressBar;
    	private: System::Windows::Forms::ProgressBar^  LumiProgressBar;
     
    	private: System::Windows::Forms::TrackBar^  DiffTrackBar;
    	private: System::Windows::Forms::TrackBar^  LumiTrackBar;
    	private: System::Windows::Forms::Label^  CountDownEdit;
    	private:
    		/// <summary>
    		/// Variable nécessaire au concepteur.
    		/// </summary>
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
    		/// le contenu de cette méthode avec l'éditeur de code.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->CloseButton = (gcnew System::Windows::Forms::Button());
    			this->StartStopButton = (gcnew System::Windows::Forms::Button());
    			this->PreferenceButton = (gcnew System::Windows::Forms::Button());
    			this->DiffProgressBar = (gcnew System::Windows::Forms::ProgressBar());
    			this->LumiProgressBar = (gcnew System::Windows::Forms::ProgressBar());
    			this->DiffTrackBar = (gcnew System::Windows::Forms::TrackBar());
    			this->LumiTrackBar = (gcnew System::Windows::Forms::TrackBar());
    			this->CountDownEdit = (gcnew System::Windows::Forms::Label());
    			this->DiffEdit = (gcnew System::Windows::Forms::Label());
    			this->LumiEdit = (gcnew System::Windows::Forms::Label());
    			this->AlertDiff = (gcnew System::Windows::Forms::TextBox());
    			this->AlertLum = (gcnew System::Windows::Forms::TextBox());
    			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->DiffTrackBar))->BeginInit();
    			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->LumiTrackBar))->BeginInit();
    			this->SuspendLayout();
    			// 
    			// CloseButton
    			// 
    			this->CloseButton->Location = System::Drawing::Point(172, 12);
    			this->CloseButton->Name = L"CloseButton";
    			this->CloseButton->Size = System::Drawing::Size(160, 33);
    			this->CloseButton->TabIndex = 0;
    			this->CloseButton->Text = L"Quitter";
    			this->CloseButton->UseVisualStyleBackColor = true;
    			this->CloseButton->Click += gcnew System::EventHandler(this, &MainForm::CloseButton_Click);
    			// 
    			// StartStopButton
    			// 
    			this->StartStopButton->Location = System::Drawing::Point(15, 12);
    			this->StartStopButton->Name = L"StartStopButton";
    			this->StartStopButton->Size = System::Drawing::Size(151, 33);
    			this->StartStopButton->TabIndex = 1;
    			this->StartStopButton->Text = L"Démarrer";
    			this->StartStopButton->UseVisualStyleBackColor = true;
    			this->StartStopButton->Click += gcnew System::EventHandler(this, &MainForm::StartStopButton_Click);
    			// 
    			// PreferenceButton
    			// 
    			this->PreferenceButton->Location = System::Drawing::Point(350, 12);
    			this->PreferenceButton->Name = L"PreferenceButton";
    			this->PreferenceButton->Size = System::Drawing::Size(88, 24);
    			this->PreferenceButton->TabIndex = 2;
    			this->PreferenceButton->Text = L"Préférences";
    			this->PreferenceButton->UseVisualStyleBackColor = true;
    			this->PreferenceButton->Visible = false;
    			this->PreferenceButton->Click += gcnew System::EventHandler(this, &MainForm::PreferenceButton_Click);
    			// 
    			// DiffProgressBar
    			// 
    			this->DiffProgressBar->Location = System::Drawing::Point(12, 104);
    			this->DiffProgressBar->Name = L"DiffProgressBar";
    			this->DiffProgressBar->Size = System::Drawing::Size(320, 50);
    			this->DiffProgressBar->TabIndex = 3;
    			// 
    			// LumiProgressBar
    			// 
    			this->LumiProgressBar->Location = System::Drawing::Point(405, 104);
    			this->LumiProgressBar->Name = L"LumiProgressBar";
    			this->LumiProgressBar->Size = System::Drawing::Size(320, 50);
    			this->LumiProgressBar->TabIndex = 4;
    			// 
    			// DiffTrackBar
    			// 
    			this->DiffTrackBar->Location = System::Drawing::Point(12, 51);
    			this->DiffTrackBar->Maximum = 100;
    			this->DiffTrackBar->Name = L"DiffTrackBar";
    			this->DiffTrackBar->Size = System::Drawing::Size(320, 45);
    			this->DiffTrackBar->TabIndex = 7;
    			this->DiffTrackBar->Value = ReadCurrentDiff();
    			this->DiffTrackBar->Scroll += gcnew System::EventHandler(this, &MainForm::DiffTrackBar_Scroll);
    			// 
    			// LumiTrackBar
    			// 
    			this->LumiTrackBar->Location = System::Drawing::Point(405, 51);
    			this->LumiTrackBar->Maximum = 100;
    			this->LumiTrackBar->Name = L"LumiTrackBar";
    			this->LumiTrackBar->Size = System::Drawing::Size(320, 45);
    			this->LumiTrackBar->TabIndex = 8;
    			this->LumiTrackBar->Value = ReadCurrentLum();
    			this->LumiTrackBar->Scroll += gcnew System::EventHandler(this, &MainForm::LumiTrackBar_Scroll);
    			// 
    			// CountDownEdit
    			// 
    			this->CountDownEdit->AutoSize = true;
    			this->CountDownEdit->Location = System::Drawing::Point(310, 450);
    			this->CountDownEdit->Name = L"CountDownEdit";
    			this->CountDownEdit->Size = System::Drawing::Size(0, 13);
    			this->CountDownEdit->TabIndex = 10;
    			// 
    			// DiffEdit
    			// 
    			this->DiffEdit->AutoSize = true;
    			this->DiffEdit->Location = System::Drawing::Point(12, 83);
    			this->DiffEdit->Name = L"DiffEdit";
    			this->DiffEdit->Size = System::Drawing::Size(175, 13);
    			this->DiffEdit->TabIndex = 11;
    			this->DiffEdit->Text = L"Seuil";
    			// 
    			// LumiEdit
    			// 
    			this->LumiEdit->AutoSize = true;
    			this->LumiEdit->Location = System::Drawing::Point(402, 83);
    			this->LumiEdit->Name = L"LumiEdit";
    			this->LumiEdit->Size = System::Drawing::Size(191, 13);
    			this->LumiEdit->TabIndex = 12;
    			this->LumiEdit->Text = L"Luminosité";
    			// 
    			// AlertDiff
    			// 
    			this->AlertDiff->BorderStyle = System::Windows::Forms::BorderStyle::None;
    			this->AlertDiff->Enabled = false;
    			this->AlertDiff->Location = System::Drawing::Point(130, 123);
    			this->AlertDiff->Name = L"AlertDiff";
    			this->AlertDiff->Size = System::Drawing::Size(55, 13);
    			this->AlertDiff->TabIndex = 13;
    			// 
    			// AlertLum
    			// 
    			this->AlertLum->BorderStyle = System::Windows::Forms::BorderStyle::None;
    			this->AlertLum->Enabled = false;
    			this->AlertLum->Location = System::Drawing::Point(537, 123);
    			this->AlertLum->Name = L"AlertLum";
    			this->AlertLum->Size = System::Drawing::Size(53, 13);
    			this->AlertLum->TabIndex = 14;
    			// 
    			// MainForm
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(743, 483);
    			this->Controls->Add(this->AlertLum);
    			this->Controls->Add(this->AlertDiff);
    			this->Controls->Add(this->LumiEdit);
    			this->Controls->Add(this->DiffEdit);
    			this->Controls->Add(this->CountDownEdit);
    			this->Controls->Add(this->LumiTrackBar);
    			this->Controls->Add(this->DiffTrackBar);
    			this->Controls->Add(this->LumiProgressBar);
    			this->Controls->Add(this->DiffProgressBar);
    			this->Controls->Add(this->PreferenceButton);
    			this->Controls->Add(this->StartStopButton);
    			this->Controls->Add(this->CloseButton);
    			this->DoubleBuffered = true;
    			this->MaximizeBox = false;
    			this->MaximumSize = System::Drawing::Size(800, 600);
    			this->MinimizeBox = false;
    			this->MinimumSize = System::Drawing::Size(700, 500);
    			this->Name = L"MainForm";
    			this->Text = L"Fenêtre principale";
    			this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load);
    			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->DiffTrackBar))->EndInit();
    			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->LumiTrackBar))->EndInit();
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion

  8. #8
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Je ne suis pas du tout familier avec cette syntaxe, mais
    private: System::Windows::Forms::Button^ CloseButton;me semble concorder avec ce que je dis plus haut.
    Si ton attribut est private, tu n'y accèdes pas depuis l'extérieur de la classe.
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2006
    Messages : 147
    Points : 84
    Points
    84
    Par défaut
    Ca me semble également logique.
    Mais pourquoi est-ce private ? C'est du code généré par l'IDE apparemment. Peut-on passer la déclaration à Public ?

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    147
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2006
    Messages : 147
    Points : 84
    Points
    84
    Par défaut
    En fait je viens de mettre public à la place de private au niveau du CloseButon.
    Ca ne change absolument rien

  11. #11
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Ensuite,

    l'accès à ta classe me semble étrange.
    Tu as une méthode getWin() que tu n'utilises pas.

    WMain::MainForm::CloseButton->texttu accèdes à un attribut static nommé CloseButton de la classe MainForm

    Ca n'existe pas.
    CloseButton est un attribut d'une instance de MainForm.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WMain::MainForm::getWin()->CloseButton->text
    Qui nécessite toujours que CloseButton soit public, ou un getter.

    Finalement ton problème est loin d'être un problème windows form amha..

    Tu devrais revoir les définitions de static, attributs et méthodes de classe.
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

Discussions similaires

  1. [Débutant] comment faire pour modifier le texte des controles situés dans un about box ?
    Par glennog dans le forum Général Dotnet
    Réponses: 1
    Dernier message: 25/04/2013, 22h45
  2. Réponses: 3
    Dernier message: 31/01/2008, 10h09
  3. Comment modifier l'affichage des objets cachés de Windows ?
    Par maximdus dans le forum API, COM et SDKs
    Réponses: 23
    Dernier message: 23/07/2005, 11h45

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