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 / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

Toolbar and Windows Forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alfredo Barrientos - 12 Dec 2005 15:29 GMT
Hi,

I have a little trouble trying to assign a Toolbar control to another
toolbar variable control.

I am getting my forms controls with this:

for (int j = 0; j <= frmChild.Controls.Count - 1; j++)
{
       // Some operations

       if (ctrl.GetType().ToString() ==
"System.Windows.Forms.ToolBar")
       {
    MessageBox.Show("paso");
    System.Windows.Forms.ToolBar toolBarX = ctrl;
       }
}

I just want to access to the "buttons" property of my toolbar control,
in order to enabled or disabled toolbar buttons getting their tag
names.

Is it possible?

Thanks,

Alfredo Barrientos
Brendan Grant - 12 Dec 2005 21:05 GMT
I’m guessing that you are getting a compile error, something to the effect of:

Cannot implicitly convert type 'System.Windows.Forms.Control' to
'System.Windows.Forms.ToolBar'?

To fix that, you need to cast the reference you’ve got to your toolbar to an
actual toolbar... to do so, we’d change your line from:

System.Windows.Forms.ToolBar toolBarX = ctrl;

to

System.Windows.Forms.ToolBar toolBarX = (System.Windows.Forms.ToolBar)ctrl;

Note: You can drop the ‘System.Windows.Forms’ part if you’ve already got
that namespace being used.

Also, a couple of other quick thoughts... rather than compare each control
based on the types name... you could simply interrogate the object to
determine if it is the desired type ala:

if (ctrl is System.Windows.Forms.ToolBar)

Brendan

> Hi,
>
[quoted text clipped - 24 lines]
>
> Alfredo Barrientos

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.