471,603 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,603 software developers and data experts.

Toolbar and Windows Forms

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

Dec 12 '05 #1
1 3299
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
"Alfredo Barrientos" wrote:
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

Dec 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jason Tabert | last post: by
5 posts views Thread by anthony.duerr | last post: by
9 posts views Thread by Hugh | last post: by
4 posts views Thread by Fredrik Melin | last post: by
3 posts views Thread by Flashster | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by

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.