我在C+;中创建单击事件时遇到一些问题+; 我在VisualStudio 2008 C++中在文本框上创建了一个点击事件。我有一个文本框数组,需要在单击事件时添加到其中。我试着这样做:
点击功能:我在C+;中创建单击事件时遇到一些问题+; 我在VisualStudio 2008 C++中在文本框上创建了一个点击事件。我有一个文本框数组,需要在单击事件时添加到其中。我试着这样做:,c++,visual-studio,events,textbox,click,C++,Visual Studio,Events,Textbox,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 &
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;
}
第二个问题比第一个问题更重要:
如果有人知道可以在文本框上创建一个单击事件,该事件将具有一个包含其他参数的函数,
System::Object^sender,System::EventArgs^e
,类似这样的内容:void ClickBtn(int-value,String^something)
我设法解决了这个问题
创建单击事件的正确代码为:
this->text\u edit[i]->Click+=gcnew System::EventHandler(this,&DataView\u Form::TextBoxClick)代码>
而TextBoxClick
是问题中的功能按钮ClickHandler
DataView\u表单
是我的表单:
public ref class DataView\u Form:public System::Windows::Forms::Form
{
//代码在这里
};代码>它说,New
不存在。New
是否存在?是否在某处定义了New
?可能您没有包含必要的标题?我使用的代码与您创建文本框时在生成代码中使用的代码相同,我不知道新代码是什么,但在生成的代码中没有定义。也许您应该在代码中查找new::ButtonClickHandler
,看看是否定义了它。如果是,您应该知道在与您正在处理的窗口对应的*.h文件中包含哪个文件。不要使用New::ButtonClickHandler。
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