-
October 15th, 2012, 05:33 AM
#1
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?
-
October 15th, 2012, 07:09 AM
#2
Re: array of buttons... click event ?
Bad forum. You need to switch to Managed C++.
Best regards,
Igor
-
October 15th, 2012, 07:40 AM
#3
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:
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;
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
October 15th, 2012, 10:13 AM
#4
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?
Last edited by FenixEden; October 15th, 2012 at 10:17 AM.
Reason: code doesn't work
-
October 15th, 2012, 11:23 AM
#5
Re: array of buttons... click event ?
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...
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);
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|