Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Toolbar question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Water Cooler v2 - 18 Jul 2006 15:13 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
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();
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.