0

我在 Visual Studio 2008 C++ 中在 TextBox 上创建 Click 事件时遇到问题。我有一个文本框数组,我需要在 Click 事件中添加它们。我以这种方式尝试:

点击功能:

private: System::Void ButtonClickHandler(System::Object^  sender, System::EventArgs^  e) 
{
    //something   

}

创建点击事件的代码:

this->text_edit[i]->Click +=gcnew System::EventHandler(this, &New::ButtonClickHandler);

代码在此用于:

for(i=0; i < howMany; i++)
{
    this->text_edit[i]=(gcnew System::Windows::Forms::TextBox());  
    this->text_edit[i]->AutoSize = true;  
    this->text_edit[i]->Location = System::Drawing::Point(where_X_Edit, where_Y_Edit);  
    this->text_edit[i]->Name = interf[i];  
    this->text_edit[i]->Size = System::Drawing::Size(90, 30);  
    this->text_edit[i]->TabIndex = 0;  
    this->text_edit[i]->Text = interf[i];
    this->text_edit[i]->Enabled=false;

    this->text_edit[i]->Click +=gcnew System::EventHandler(this, &New::ButtonClickHandler);

    panel->Controls->Add(this->text_edit[i]);
    where_Y_Edit += 32; 
}

问题在于创建点击事件,仅在该行代码中出现 9 个错误。

Error   2   error C2653: 'New' : is not a class or namespace name   c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   3   error C2276: '&' : illegal operation on bound member function expression    c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   4   error C3350: 'System::EventHandler' : a delegate constructor expects 2 argument(s)  c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   13  error C2653: 'New' : is not a class or namespace name   c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   14  error C2276: '&' : illegal operation on bound member function expression    c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   15  error C3350: 'System::EventHandler' : a delegate constructor expects 2 argument(s)  c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   17  error C2653: 'New' : is not a class or namespace name   c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   18  error C2276: '&' : illegal operation on bound member function expression    c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502
Error   19  error C3350: 'System::EventHandler' : a delegate constructor expects 2 argument(s)  c:\users\uidw7119\documents\visual studio 2008\projects\datalogger\datalogger\DataView_Form.h   502

第二个问题比第一个问题更重要:如果有人知道可以在 TextBox 上创建一个 Click 事件,该事件将具有一个带有其他参数的函数System::Object^ sender, System::EventArgs^ e,例如:void ClickBtn(int value, String ^ something)

4

1 回答 1

0

我设法解决了这个问题。

创建 Click 事件的正确代码是:

this->text_edit[i]->Click += gcnew System::EventHandler(this, &DataView_Form::TextBoxClick);

并且TextBoxClickButtonClickHandler问题的功能。

DataView_Form是我的表格:

public ref class DataView_Form : public System::Windows::Forms::Form { //code here };

于 2013-08-01T10:49:07.313 回答