tags:

views:

47

answers:

1

I have made one function named SetControls(control controlName) which only takes control as a argument.And I want to pass the toolstripbutton which is in the tooltipcontainer.Function SetControls() consider toolstripContainer but does not consider toolstripbutton as control and there is error if I pass the toolstripbutton as control.

Then what should I do ? Shoud I convert the toolstripbutton as control, if yes then how??

+2  A: 

The problem you are having is because ToolStripButton inherits from Component and not Control. The standard System.Windows.Forms.Button inherits from Control which in turn inherits from Component. You would have to change SetControls from:

SetControls(Control controlName)

to

SetControls(Component componentName)

if you want to use the method to handle both standard controls and ToolStripButton's.

Adam Gritt
If I change the method then control can be passed to the parameter component.Will control be considered as a component??
Harikrishna
As Control directly inherits from Component you will only be able to access whatever methods/properties are available to a Component. If you need access to methods/properties that are on a Control you will need to keep the method that takes a Control to handle those cases. You may need two methods in the end. One that takes of type Control and one that takes of type ToolStripItem and set the information for each type appropriately.
Adam Gritt
Nah, create an overload of SetControls that takes a ToolStripItem.
Hans Passant
Is it possible to convert the components to control?
Harikrishna
It is possible to up-cast a Component to a Control but if the item doesn't inherit from Control (ie ToolStripButton) then the result of the cast will be NULL.
Adam Gritt