tags:

views:

22

answers:

1

First of, is making a Windows Form Application from the CLR section in the new project window called .NET or something else? I just want to know so I can search things on it better.

How do I distinguish between the individual buttons if I gave them both the same click function?

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));
}

};

That shows me System.Windows.Forms.Button, Text:button1 or button2

Fastest method I thought of was to do if statements using the Text but how do I actually access the Text property of the sender object?

Edit: Maybe I'm doing it wrong but I added

Button button = sender as Button

right above the MessageBox line and I got

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'
+2  A: 

How do I distinguish between the individual buttons if I gave them both the same click function?

by sender

how do I actually access the Text property of the sender object? convert sender to Button type and call Text property.

Button^ button = (Button^)sender ;
button->Text;

actually it's not good idea to search buttons by Text prop. you'd better search by Name or Id.

Arseny
It worked! Though I don't see ID anywhere, I can only find Name and TabIndex.
TreeTree