Cambiare testo form a runtime Visual C++ 2019

di il
1 risposte

Cambiare testo form a runtime Visual C++ 2019

Ciao a tutti, ho scaricato da poco visual c++ 2019, molto diverso da visual c++ 6... e non riesco a capire come si cambia la proprietà Text a runtime di una windows form dopo la pressione di un pulsante... qualcuno di voi mi saprebbe aiutare? Grazie mille!
Il testo della form deve essere cambiato all'interno di questo metodo, ma il puntatore this non ha visibilità
private: System::Void SinistraBtn_Click(System::Object^ sender, System::EventArgs^ e) {
}
	   
};
Vi posto anche il resto del codice per maggiore comprensione

#pragma once

namespace CppCLRWinformsProjekt {

	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>
	/// Zusammenfassung für Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:

		

		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
			
		}

	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^ AbilitaBtn;
	protected:
	private: System::Windows::Forms::Button^ NascondiBtn;
	private: System::Windows::Forms::Button^ SinistraBtn;
	private: System::Windows::Forms::Button^ CentroBtn;
	private: System::Windows::Forms::Button^ DestraBtn;

	protected:

	private:
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </summary>
		void InitializeComponent(void)
		{
			this->AbilitaBtn = (gcnew System::Windows::Forms::Button());
			this->NascondiBtn = (gcnew System::Windows::Forms::Button());
			this->SinistraBtn = (gcnew System::Windows::Forms::Button());
			this->CentroBtn = (gcnew System::Windows::Forms::Button());
			this->DestraBtn = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// AbilitaBtn
			// 
			this->AbilitaBtn->Location = System::Drawing::Point(31, 22);
			this->AbilitaBtn->Name = L"AbilitaBtn";
			this->AbilitaBtn->Size = System::Drawing::Size(75, 23);
			this->AbilitaBtn->TabIndex = 0;
			this->AbilitaBtn->Text = L"Disabilita";
			this->AbilitaBtn->UseVisualStyleBackColor = true;
			this->AbilitaBtn->Click += gcnew System::EventHandler(this, &Form1::AbilitaBtn_Click);
			// 
			// NascondiBtn
			// 
			this->NascondiBtn->Location = System::Drawing::Point(150, 22);
			this->NascondiBtn->Name = L"NascondiBtn";
			this->NascondiBtn->Size = System::Drawing::Size(75, 23);
			this->NascondiBtn->TabIndex = 1;
			this->NascondiBtn->Text = L"Nascondi";
			this->NascondiBtn->UseVisualStyleBackColor = true;
			// 
			// SinistraBtn
			// 
			this->SinistraBtn->Location = System::Drawing::Point(31, 194);
			this->SinistraBtn->Name = L"SinistraBtn";
			this->SinistraBtn->Size = System::Drawing::Size(75, 23);
			this->SinistraBtn->TabIndex = 2;
			this->SinistraBtn->Text = L"Sinistra";
			this->SinistraBtn->UseVisualStyleBackColor = true;
			this->SinistraBtn->Click += gcnew System::EventHandler(this, &Form1::SinistraBtn_Click);
			// 
			// CentroBtn
			// 
			this->CentroBtn->Location = System::Drawing::Point(166, 194);
			this->CentroBtn->Name = L"CentroBtn";
			this->CentroBtn->Size = System::Drawing::Size(75, 23);
			this->CentroBtn->TabIndex = 3;
			this->CentroBtn->Text = L"Centro";
			this->CentroBtn->UseVisualStyleBackColor = true;
			// 
			// DestraBtn
			// 
			this->DestraBtn->Location = System::Drawing::Point(306, 194);
			this->DestraBtn->Name = L"DestraBtn";
			this->DestraBtn->Size = System::Drawing::Size(75, 23);
			this->DestraBtn->TabIndex = 4;
			this->DestraBtn->Text = L"Destra";
			this->DestraBtn->UseVisualStyleBackColor = true;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(467, 261);
			this->Controls->Add(this->DestraBtn);
			this->Controls->Add(this->CentroBtn);
			this->Controls->Add(this->SinistraBtn);
			this->Controls->Add(this->NascondiBtn);
			this->Controls->Add(this->AbilitaBtn);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			

		}
#pragma endregion
	
	private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

		
	}

		   
	private: System::Void AbilitaBtn_Click(System::Object^ sender, System::EventArgs^ e) {

		bool enabled = SinistraBtn->Enabled;

		SinistraBtn->Enabled = !enabled;
		CentroBtn->Enabled = !enabled;
		DestraBtn->Enabled = !enabled;

		if (!enabled) AbilitaBtn->Text = "Disabilita";
		else AbilitaBtn->Text = "Abilita";
		
	}
private: System::Void SinistraBtn_Click(System::Object^ sender, System::EventArgs^ e) {
}
	   
};
}

1 Risposte

Devi accedere o registrarti per scrivere nel forum
1 risposte