PDA

Click to See Complete Forum and Search --> : toolbar problem {Resolved}


steve_rm
Nov 28th, 2003, 05:04 AM
Thanks for you help

I have used the code below based on what you told me. It works fine.


switch (e.Button.Tag.ToString())



Hello

I have a toolbar with some icons on it. I want to click on of the icons and open that from. But my swich statement does not work, as it asks for a integer.

code below


private void tbrIcons_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (e.Button)//problem here, what am l doing wrong
{
case "house":
//Show house form
break;
case "village":
//show village form
break;
default:
break;
}
}


many thanks in advance

Steve

Sgt-Peppa
Nov 28th, 2003, 06:24 AM
switch (e.Button.Text.ToString())//problem here, what am l doing wrong
{
case "house":
MessageBox.Show("House");
break;
case "village":
//show village form
break;
default:
MessageBox.Show("Else");
break;
}



That should work,

HTH,

Stephan

dynamic_sysop
Nov 28th, 2003, 06:25 AM
you need to specify more than just e.Button , eg:

private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(e.Button.Text) // you can also put e.Button.Name here , or Tag etc. ..
{
case "house" :
MessageBox.Show("you just clicked the button with the text ---house!");
break;
case "village" :
MessageBox.Show("you just clicked the button with the text ---village!");
break;
}
}