[WinForm/VS2005] Instantier une classe
Résolu
skarsnick
Messages postés
79
Date d'inscription
Statut
Membre
Dernière intervention
-
skarsnick Messages postés 79 Date d'inscription Statut Membre Dernière intervention -
skarsnick Messages postés 79 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Mon problème est tout con je pense, mais je me prend un peu la tête avec :p
j'ai commencé un projet WinForm, ou j'ai défini un label:
Voici le code du Form1.h:
Voici le code du Test.cpp:
J'aimerais, dans mon .cpp, créé un Thread qui gère dynamiquement le texte de mon label1.
un truc du genre:
System::String ^ chaine;
System::DateTime ^ date = System::DateTime::Now;
chaine = date->ToString();
this->label1->Text = chaine;
Le seul hic et vous l'aurez deviné c'est que le "this->label1->Text" ça lui dit rien du tout.
Comment faire pour faire changer le texte de ce label?
J'ai trouvé un bon tuto: https://nico-pyright.developpez.com/tutoriel/vc2005/winforms/#LhelloWorld mais tous les lien vers MSDN sont cassé et je me suis noyé dans les lib sans trouver ce que je voulais
Merci de votre aide!
Mon problème est tout con je pense, mais je me prend un peu la tête avec :p
j'ai commencé un projet WinForm, ou j'ai défini un label:
Voici le code du Form1.h:
namespace Test { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: ~Form1() { if (components) { delete components; } } public: System::Windows::Forms::Label^ label1; protected: private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->label1 = (gcnew System::Windows::Forms::Label()); this->SuspendLayout(); // // label1 // this->label1->AccessibleName = L"jesaipas"; this->label1->AccessibleRole = System::Windows::Forms::AccessibleRole::Text; this->label1->AutoSize = true; this->label1->BackColor = System::Drawing::Color::Transparent; this->label1->Cursor = System::Windows::Forms::Cursors::No; this->label1->ForeColor = System::Drawing::SystemColors::ControlLightLight; this->label1->Location = System::Drawing::Point(668, 516); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(41, 13); this->label1->TabIndex = 0; this->label1->Text = L"testons"; this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click); } }; }
Voici le code du Test.cpp:
#include "stdafx.h" #include "Form1.h" using namespace Test; [STAThreadAttribute] int main(array<System::String ^> ^args) { // Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // Create the main window and run it Application::Run(gcnew Form1()); return 0; }
J'aimerais, dans mon .cpp, créé un Thread qui gère dynamiquement le texte de mon label1.
un truc du genre:
System::String ^ chaine;
System::DateTime ^ date = System::DateTime::Now;
chaine = date->ToString();
this->label1->Text = chaine;
Le seul hic et vous l'aurez deviné c'est que le "this->label1->Text" ça lui dit rien du tout.
Comment faire pour faire changer le texte de ce label?
J'ai trouvé un bon tuto: https://nico-pyright.developpez.com/tutoriel/vc2005/winforms/#LhelloWorld mais tous les lien vers MSDN sont cassé et je me suis noyé dans les lib sans trouver ce que je voulais
Merci de votre aide!
A voir également:
- [WinForm/VS2005] Instantier une classe
- Classe ram - Guide
- Bluetooth mercedes classe a - Forum Autoradio
- Dans le code de la page, modifiez la couleur de fond de la classe .pix. - Forum Réseaux sociaux
- Sti2d classe poubelle - Forum Programmation
- Retrouver la liste des élèves d'une classe - Forum Loisirs / Divertissements
1 réponse
Voilà comment faire pour ceux qui recherche:
private: System::Void TimerDate1s_Tick(System::Object^ sender, System::EventArgs^ e)
{
System::String ^ date;
date = System::DateTime::Now.ToString("yyyy/MM/dd \nHH:mm");
this->Date->Text = date;
}
La fonction TimerDate1s_Tick est appelée par un Tick toutes les Secondes
private: System::Void TimerDate1s_Tick(System::Object^ sender, System::EventArgs^ e)
{
System::String ^ date;
date = System::DateTime::Now.ToString("yyyy/MM/dd \nHH:mm");
this->Date->Text = date;
}
La fonction TimerDate1s_Tick est appelée par un Tick toutes les Secondes