Я уже спрашивал что-то подобное, но решение, которое я нашел, помогает мне частично, поэтому я задаю вопрос, который похож на мой предыдущий.моя проблема в том, что в теме я хочу чтобы текст кнопки менялся.поток работает нормально, я вижу MessageBox, который я показываю, но текст кнопки остается неизменным.как я могу это изменить?если мне нужно использовать делегата (закомментированный текст), как я могу это исправить?потому что этот код вызывает некоторые ошибки о неправильном '(' и '{', но этот ответ я получил раньше
#pragma once
namespace UIThread {
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::Threading;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ BtnStart;
protected:
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->BtnStart = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// BtnStart
//
this->BtnStart->Location = System::Drawing::Point(114, 38);
this->BtnStart->Name = L"BtnStart";
this->BtnStart->Size = System::Drawing::Size(124, 37);
this->BtnStart->TabIndex = 0;
this->BtnStart->Text = L"button1";
this->BtnStart->UseVisualStyleBackColor = true;
this->BtnStart->Click += gcnew System::EventHandler(this, &Form1::BtnStart_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->BtnStart);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void BtnStart_Click(System::Object^ sender, System::EventArgs^ e) {
Form1^ f=gcnew Form1;
Thread^ oThread = gcnew Thread( gcnew ThreadStart( f, &Form1::ThreadMethod ) );
oThread->Start();
}
private: void ThreadMethod(/*Object^ state*/)
{
BtnStart->Text="hello";
MessageBox::Show("AAAAAA");
//this->Invoke((Action^)delegate(){BtnStart->Text = "Hello";});
}
};
}