array of buttons... click event ?
Hi I have successfully compiled a code where I created an array of buttons.
I have added a click event to it like this :
Code:
buttons[indexofhashis2]->Click += gcnew System::EventHandler(this, &Execute::GOBUT_Click);
I have a standard event like this
Code:
private: System::Void GOBUT_Click(System::Object^ sender, System::EventArgs^ e) {
int x;
x = sender->Location.X;
}
returns error saying Location is not a member of Object^.
If you don't understand what i want to do :
I'm trying to create an array of button (user/runtime created buttons) and get different interpretations of the click event depending of wich button is clicked.
For example, if we create buttons[0] I wish to get the 0 or something relevant into the GOBUT_Click event.
Any one knows how to do that?
Re: array of buttons... click event ?
Bad forum. You need to switch to Managed C++.
Re: array of buttons... click event ?
Igor is right about that you posted this in the wrong place. However, the anser is short, so I'll post it here right away:
Quote:
Originally Posted by
FenixEden
[...] returns error saying Location is not a member of Object^.
Correct: Is isn't. You need to cast the parameter to Control ^ (or a more specific class like Button ^) in order to access control members:
Code:
x = safe_cast<Control ^>(sender)->Location.X;
Re: array of buttons... click event ?
I think you're right for Managed C++,
however this forum is mostly empty, I think I would not get an answer there.
And so...
Okay!!!
I need to associate the click on those buttons arrays to the correct interpretation in the GO_BUT::Click event.
So how I do that?
Is it like this or something like that?
Code:
private: System::Void GOBUT_Click(System::Object^ sender, System::EventArgs^ e) {
int ID;
Button^ IDBut;
IDBut = sender;
EDIT : Returns conversion error. Object^ to Button^
How can I associate the right index of my button array to it?
Re: array of buttons... click event ?
Quote:
Originally Posted by
FenixEden
I think you're right for Managed C++,
however this forum is mostly empty, I think I would not get an answer there.
Sure you will. Trust me... :cool:
Quote:
EDIT : Returns conversion error. Object^ to Button^
How can I associate the right index of my button array to it?
Not really surprising: You're trying to do a plain assignment instead of casting (see my example in post #3). In the context of your latest snippet, you need to change the offending line to this:
Code:
IDBut = safe_cast<Button ^>(sender);