Visual c++ C++。NET是否为两个按钮提供相同的单击功能?
首先,是从新项目窗口中的CLR部分生成名为.NET的Windows窗体应用程序还是其他什么?我只是想知道,这样我可以在上面更好地搜索东西 如果我给了两个按钮相同的点击功能,如何区分它们Visual c++ C++。NET是否为两个按钮提供相同的单击功能?,visual-c++,Visual C++,首先,是从新项目窗口中的CLR部分生成名为.NET的Windows窗体应用程序还是其他什么?我只是想知道,这样我可以在上面更好地搜索东西 如果我给了两个按钮相同的点击功能,如何区分它们 this->button1->Click += gcnew System::EventHandler(this, &test::button1_Click); this->button2->Click += gcnew System::EventHandler(this, &
this->button1->Click += gcnew System::EventHandler(this, &test::button1_Click);
this->button2->Click += gcnew System::EventHandler(this, &test::button1_Click);
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show (Convert::ToString (sender));
}
})
显示System.Windows.Forms.Button,文本:button1或button2
我想到的最快的方法是使用文本执行if语句,但如何实际访问发送方对象的Text属性呢
编辑:
也许我做错了,但我补充道
Button button = sender as Button
就在留言栏的上方,我得到了
System::Windows::Forms::Button' : class does not have a copy-constructor
syntax error : missing ';' before identifier 'as'
error C2065: 'as' : undeclared identifier
syntax error : missing ';' before identifier 'Button'
System::Windows::Forms::Button' : illegal use of this type as an expression
see declaration of 'System::Windows::Forms::Button'
如果我给了两个按钮相同的点击功能,如何区分它们
this->button1->Click += gcnew System::EventHandler(this, &test::button1_Click);
this->button2->Click += gcnew System::EventHandler(this, &test::button1_Click);
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show (Convert::ToString (sender));
}
寄件人
如何实际访问发送者对象的文本属性?
将发件人转换为按钮类型并调用文本属性
实际上,用文本属性搜索按钮不是个好主意。您最好按姓名或Id进行搜索。可能是标签
managed-c++
?它起作用了!虽然我在任何地方都看不到ID,但我只能找到Name和TabIndex。