Besides querying the Text property, how do you find out which button on
the toolbar has been clicked? The Name property doesn't appear in the
code window, but only appears in the design mode.
The problem is that I have added a lot of spaces to the left of the
label of one of my buttons. The actual label text I have entered in the
design mode is " Exit Map".
When I query this:
else if (e.Button.Text.Trim() == "Exit Map")
{
this.Dispose();
this.Close();
}
The code skips this condition altogether. For the other labels, it
enters the construct as it should. I am a bit confused.
Water Cooler v2 - 18 Jul 2006 15:38 GMT
My bad! I had an extra space in between the two words.
WhiteWizard - 18 Jul 2006 15:53 GMT
I couldn't duplicate your problem, my code worked just fine, but to avoid it
you could use the TAG property instead.
HTH
WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
> Besides querying the Text property, how do you find out which button on
> the toolbar has been clicked? The Name property doesn't appear in the
[quoted text clipped - 14 lines]
> The code skips this condition altogether. For the other labels, it
> enters the construct as it should. I am a bit confused.
ChrisM - 18 Jul 2006 16:44 GMT
> Besides querying the Text property, how do you find out which button on
> the toolbar has been clicked? The Name property doesn't appear in the
[quoted text clipped - 14 lines]
> The code skips this condition altogether. For the other labels, it
> enters the construct as it should. I am a bit confused.
What may be easier is to use code similar to this:
else if (myToolBar.Buttons.IndexOf(e.Button) = 1); // Or whatever the index
of your 'Exit Map' button is.
That way, if you change the text on the button, you won't need to worry
about changing the code.
Cheers,
Chris.
WhiteWizard - 18 Jul 2006 18:26 GMT
Chris is right, but I would disagree. It is far more likely that I would add
a button, thereby having to go and change all my "IndexOf" statements, than
have to change the text of a button a user is already using.
If you use the Tag property you avoid both problems, since the tag won't be
seen by the user, and I can assign a unique value to each and never have to
worry about adding buttons OR changing indexes.
IMHO of course ;)
WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
> > Besides querying the Text property, how do you find out which button on
> > the toolbar has been clicked? The Name property doesn't appear in the
[quoted text clipped - 26 lines]
>
> Chris.
ChrisM - 19 Jul 2006 09:41 GMT
Hmmm,
Thinking about it, I have to agree that using Tag is probably the best
maintenance friendly option :-)
Chris.
> Chris is right, but I would disagree. It is far more likely that I would
> add
[quoted text clipped - 45 lines]
>>
>> Chris.
Roger - 19 Jul 2006 00:19 GMT
> else if (e.Button.Text.Trim() == "Exit Map")
> {
> this.Dispose();
> this.Close();
> }
Unless you're adding tool bar buttons dynamically at run-time, just
give all of your buttons descriptive names and compare the object
references:
ToolBarButton _button1;
.
.
.
if( e.Button == _button1 )
{
DoStuff();
}