There is a class Source.h
#pragma once #include "logic.h" namespace tetstst { class Sourse{ public: Sourse(); logic player1; }; } Source.cpp assigns player1 parameters
#include "Sourse.h" namespace tetstst { tetstst::Sourse::Sourse() { player1.setName("ARRA"); player1.setScore(20); } } The logic class itself looks like this
#pragma once namespace tetstst { class logic { private: int score; char* name; public: logic(); void setScore(int score); int getScore(); void setName(char*); char* getName(); ~logic(); }; } And now to the point. There is a window with a textBox in which you want to display the Score value for player1 . If in the class in which the window elements are created write
textBox1->Text = player1.getScore(); then nothing will come of it. And in this class player1 not available. What should be done?
Code MyForm.h
#pragma once #include "Sourse.h" namespace tetstst { 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> /// Сводка для MyForm /// </summary> public ref class MyForm : public System::Windows::Forms::Form{ public: MyForm(void){ InitializeComponent(); // //TODO: добавьте код конструктора // } protected: /// <summary> /// Освободить все используемые ресурсы. /// </summary> ~MyForm() { if (components) { delete components; } } private: System::Windows::Forms::TextBox^ textBox1; protected: private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Button^ button2; private: /// <summary> /// Обязательная переменная конструктора. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Требуемый метод для поддержки конструктора — не изменяйте /// содержимое этого метода с помощью редактора кода. /// </summary> void InitializeComponent(void) { this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // textBox1 // this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204))); this->textBox1->Location = System::Drawing::Point(104, 52); this->textBox1->Multiline = true; this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(264, 54); this->textBox1->TabIndex = 0; this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; this->textBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox1_TextChanged); this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress); // // button1 // this->button1->Location = System::Drawing::Point(104, 125); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(124, 50); this->button1->TabIndex = 1; this->button1->Text = L"+1"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); // // button2 // this->button2->Location = System::Drawing::Point(244, 125); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(124, 50); this->button2->TabIndex = 2; this->button2->Text = L"-1"; this->button2->UseVisualStyleBackColor = true; // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(8, 16); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(474, 249); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Controls->Add(this->textBox1); this->Name = L"MyForm"; this->Text = L"Fucking nigger"; this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { /*textBox1->Text = "123";*/ } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) { } private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { char number = e->KeyChar; if (!Char::IsDigit(number)){ e->Handled = true; } } }; }";#pragma once #include "Sourse.h" namespace tetstst { 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> /// Сводка для MyForm /// </summary> public ref class MyForm : public System::Windows::Forms::Form{ public: MyForm(void){ InitializeComponent(); // //TODO: добавьте код конструктора // } protected: /// <summary> /// Освободить все используемые ресурсы. /// </summary> ~MyForm() { if (components) { delete components; } } private: System::Windows::Forms::TextBox^ textBox1; protected: private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Button^ button2; private: /// <summary> /// Обязательная переменная конструктора. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Требуемый метод для поддержки конструктора — не изменяйте /// содержимое этого метода с помощью редактора кода. /// </summary> void InitializeComponent(void) { this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // textBox1 // this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204))); this->textBox1->Location = System::Drawing::Point(104, 52); this->textBox1->Multiline = true; this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(264, 54); this->textBox1->TabIndex = 0; this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center; this->textBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox1_TextChanged); this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress); // // button1 // this->button1->Location = System::Drawing::Point(104, 125); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(124, 50); this->button1->TabIndex = 1; this->button1->Text = L"+1"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); // // button2 // this->button2->Location = System::Drawing::Point(244, 125); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(124, 50); this->button2->TabIndex = 2; this->button2->Text = L"-1"; this->button2->UseVisualStyleBackColor = true; // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(8, 16); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(474, 249); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Controls->Add(this->textBox1); this->Name = L"MyForm"; this->Text = L"Fucking nigger"; this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { /*textBox1->Text = "123";*/ } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) { } private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { char number = e->KeyChar; if (!Char::IsDigit(number)){ e->Handled = true; } } }; }
textBox1from in C ++? What is it and what type is it? And what type oftextBox1->Text? - VladD