Which button?

  • Thread starter Thread starter Lynn Morrison
  • Start date Start date
L

Lynn Morrison

Hi, I cannot get this code to work. All I want to do is to fetch 'which'
toolbar button was clicked, so I can act on it...

private: System::Void toolBar1_Click(System::Object * sender,
System::EventArgs * e)

{

int index = toolBar1->Buttons->IndexOf(dynamic_cast<ToolBarButton
*>(e->Button));

switch(index) {

case 0:

break;

case 1:

break;

case 2:

menuItem4_Click(sender,e);

break;

case 4:

ExitmenuItem_Click(sender,e);

break;

};

}



I've tried numerous things, but to no avail.... can anyone help? I am a .NET
noob.... ;)



Lynn
 
Hi, I cannot get this code to work. All I want to do is to fetch 'which'
toolbar button was clicked, so I can act on it...

private: System::Void toolBar1_Click(System::Object * sender,
System::EventArgs * e)

{

int index = toolBar1->Buttons->IndexOf(dynamic_cast<ToolBarButton
*>(e->Button));

switch(index) {

case 0:

break;

case 1:

break;

case 2:

menuItem4_Click(sender,e);

break;

case 4:

ExitmenuItem_Click(sender,e);

break;

};

you should use following syntax:

private: System::Void toolBar1_Click(System::Object *
sender,System::EventArgs * e)
{
switch(toolBar1->Buttons->IndexOf(e->Button))
{
case 0:
action;
break;
case 1:
action;
break;

};
}

Regards, Robert Kapuscinski
 
Hi,

One thing you can do is keep references to the buttons themselves (button1,
button2 etc). You can then test ( sender == button1 ) (etc).

Steve
 
No, I tried that at first, 'C2039: e->Button is not a member of
System::EventArgs'

Thanks,

Lynn
 
That did not work, I also tried that one..
I don't get it.... its confusing to say the least... ;)

Thanks for trying,

Lynn
 
Wrong event, I tried buttonclick event instead of click event and all is
ok....

Thanks for the help guys!

Lynn
 
Back
Top