首先,是在.NET項目或其他項目的新項目窗口中從CLR部分創建一個Windows窗體應用程序?我只是想知道,所以我可以更好地搜索它。C++ .NET爲2個按鈕提供相同的點擊功能?
如果我給他們兩個相同的點擊功能,我該如何區分各個按鈕?
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
我認爲最快的方法是,如果使用文本語句做的,但實際上,我怎麼訪問發送對象的Text屬性?
編輯: 也許我做錯了,但我加
Button button = sender as Button
權在MessageBox線以上和我
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'
也許標籤'managed-C++'? – 2010-07-30 21:09:52
它被稱爲C++ CLI。 – Puppy 2010-07-31 10:18:41