问题描述
我正在 Winforms 中制作一个 GUI,并希望将单独的线程用于按钮功能。 但是无论我尝试以哪种方式实施它,我总是陷入无法解决的境地。 这是我尝试过的:
private: System::Void button1_MouseHover(System::Object ^ sender,System::EventArgs ^ e)
{
Thread^ t1 = gcnew Thread(gcnew ThreadStart( &Form1::t1));
t1->Start();
}
static void t1()
{
this->FireDrakeButton->Location = System::Drawing::Point(433,648);
Sleep(1000);
this->FireDrakeButton->Location = System::Drawing::Point(433,618);
Sleep(1000);
this->FireDrakeButton->Location = System::Drawing::Point(433,588);
}
错误(活动)E0258 'this' 只能在非静态成员函数 GUI3 中使用
如果我将 Void 设为非静态,则 Thread^ t1 函数将不起作用(出于某种原因,它仅适用于静态 void)。
private: System::Void button1_MouseHover(System::Object ^ sender,System::EventArgs ^ e)
{
std::thread t1(t1);
}
void t1()
{
this->FireDrakeButton->Location = System::Drawing::Point(433,588);
}
这里出现了这个错误。
错误 C3867 'GUI3::Form1::t1':非标准语法;使用“&”创建指向成员 GUI3 的指针
不管我把 & 放在哪里,代码都不会运行。
最后我尝试了 boost::thread,它完全无法打开。
最后,这是创建 GUI 元素的代码部分(将其缩短为我们需要的按钮)。
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^ FireDrakeButton;
private: System::Windows::Forms::Button^ LavaSlimeButton;
private: System::Windows::Forms::Button^ LavaGolemButton;
private: System::Windows::Forms::GroupBox^ Actions;
private: System::Windows::Forms::Label^ label1;
protected:
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->FireDrakeButton = (gcnew System::Windows::Forms::Button());
this->LavaSlimeButton = (gcnew System::Windows::Forms::Button());
this->LavaGolemButton = (gcnew System::Windows::Forms::Button());
this->Actions = (gcnew System::Windows::Forms::GroupBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->Actions->SuspendLayout();
this->SuspendLayout();
//
// FireDrakeButton
//
this->FireDrakeButton->Anchor = System::Windows::Forms::AnchorStyles::None;
this->FireDrakeButton->BackColor = System::Drawing::SystemColors::GradientActiveCaption;
this->FireDrakeButton->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->Getobject(L"FireDrakeButton.BackgroundImage")));
this->FireDrakeButton->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Zoom;
this->FireDrakeButton->Font = (gcnew System::Drawing::Font(L"Arial Narrow",20.25F,System::Drawing::FontStyle::Regular,System::Drawing::GraphicsUnit::Point,static_cast<System::Byte>(0)));
this->FireDrakeButton->ForeColor = System::Drawing::SystemColors::ControlText;
this->FireDrakeButton->Location = System::Drawing::Point(433,678);
this->FireDrakeButton->Name = L"FireDrakeButton";
this->FireDrakeButton->Size = System::Drawing::Size(170,236);
this->FireDrakeButton->TabIndex = 0;
this->FireDrakeButton->UseVisualStyleBackColor = false;
this->FireDrakeButton->Click += gcnew System::EventHandler(this,&Form1::FireDrakeButton_Click);
this->FireDrakeButton->MouseLeave += gcnew System::EventHandler(this,&Form1::button1_MouseLeave);
this->FireDrakeButton->MouseHover += gcnew System::EventHandler(this,&Form1::button1_MouseHover);
感谢任何帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)