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.

Re: Toolbar question by Water

Water
Tue Jul 18 09:38:53 CDT 2006

My bad! I had an extra space in between the two words.


RE: Toolbar question by WhiteWizard

WhiteWizard
Tue Jul 18 09:53:01 CDT 2006

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


"Water Cooler v2" wrote:

> 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.
>
>

Re: Toolbar question by ChrisM

ChrisM
Tue Jul 18 10:44:52 CDT 2006


"Water Cooler v2" <wtr_clr@yahoo.com> wrote in message
news:1153232028.908090.186310@m79g2000cwm.googlegroups.com...
> 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.

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.



Re: Toolbar question by WhiteWizard

WhiteWizard
Tue Jul 18 12:26:01 CDT 2006

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


"ChrisM" wrote:

>
> "Water Cooler v2" <wtr_clr@yahoo.com> wrote in message
> news:1153232028.908090.186310@m79g2000cwm.googlegroups.com...
> > 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.
>
> 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.
>
>
>

Re: Toolbar question by Roger

Roger
Tue Jul 18 18:19:55 CDT 2006

>
> 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();
}


Re: Toolbar question by ChrisM

ChrisM
Wed Jul 19 03:41:12 CDT 2006

Hmmm,

Thinking about it, I have to agree that using Tag is probably the best
maintenance friendly option :-)

Chris.


"WhiteWizard" <WhiteWizard@discussions.microsoft.com> wrote in message
news:C2F33915-E404-430C-B9C2-4B5B631EA7CE@microsoft.com...
> 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
>
>
> "ChrisM" wrote:
>
>>
>> "Water Cooler v2" <wtr_clr@yahoo.com> wrote in message
>> news:1153232028.908090.186310@m79g2000cwm.googlegroups.com...
>> > 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.
>>
>> 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.
>>
>>
>>