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