473,500 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Toolbar question

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.

Jul 18 '06 #1
6 934
My bad! I had an extra space in between the two words.

Jul 18 '06 #2
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.

Jul 18 '06 #3

"Water Cooler v2" <wt*****@yahoo.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.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.
Jul 18 '06 #4
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" <wt*****@yahoo.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.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.
Jul 18 '06 #5
>
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();
}

Jul 18 '06 #6
Hmmm,

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

Chris.
"WhiteWizard" <Wh*********@discussions.microsoft.comwrote in message
news:C2**********************************@microsof t.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" <wt*****@yahoo.comwrote in message
news:11**********************@m79g2000cwm.googleg roups.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.

Jul 19 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2334
by: Andy Bates | last post by:
I have hopefully a simple problem in C#. I designed a form with a listview on left, vert splitter against that, then the remainder of the form from top to bottom: a listview, horiz splitter and...
1
1672
by: none | last post by:
hiho@ll i want to make a IE Toolbar which has a newsticker built in the problem i have is i don't really know how to use static text in a toolbar? the second question will be, how can i change...
1
1215
by: John | last post by:
Hi all, My app is using the toolbar webcontrol. Adding to and removing from the toolbar is fine but I want to add something like an 'onclick' event to a particular toolbaritem I'm adding to the...
5
1832
by: Stewart | last post by:
Pressing a Save Button on a Toolbar will not bind or validate the last value entered in a text box. I have found that when clicking on the Toolbar the focus in the binded text box does not leave. ...
6
3882
by: =?Utf-8?B?L2Rldi9udWxs?= | last post by:
Hello, i am using visual studio 2003 enterprise architect version. I am making apps for the .Net framework 1.1. While testing an interface, i discovered something strange. In this application...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.