Setting a ToolStripStatusLabel control properties programmatically?

I have an application in which the users can control the look and feel of the application by changing properties for controls, i.e. FontBold, ForeColor, BackColor, Italics, etc.

I have a StatusStrip on my main form and it has 3 ToolStripStatusLabel within it. I can change the StatusStrip properties, however, I'm having trouble creating an instance of the ToolStripStatusLabel to change it's properties. I know this sounds pretty elementary, but it's still eluding me. Here is my code where I try to establish a new instance.

                Dim ctlType as Control

                Select Case ctlID
                    Case 1  'Buttons
                        ctlType = New Button
                    Case 2  'DataGridViews
                        ctlType = New DataGridView
                    Case 3  'GroupBoxes
                        ctlType = New GroupBox
                    Case 4  'TextBoxes
                        ctlType = New TextBox
                    Case 5  'Forms
                        ctlType = New Form
                    Case 6  'Labels
                        ctlType = New Label
                    Case 7  'ComboBoxes
                        ctlType = New ComboBox
                    Case 8  'RadioButton
                        ctlType = New RadioButton
                    Case 9  'CheckBoxes
                        ctlType = New CheckBox
                    Case 10 'TabControl
                        ctlType = New TabControl
                    Case 11 'StatusStrip
                        ctlType = New StatusStrip
                    Case 12 'MaskedTextBox
                        ctlType = New MaskedTextBox
                    Case 13 'ToolStripStatusLabel
                        ctlType = New ToolStripStatusLabel    <--- It doesn't like this declaration!
                End Select

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
This is because your variable is a Control, and the ToolStripStatusLable is not a Control.
A Control is an object that you put in a Form. The ToolStripStatusLabel does no go in a Form, it goes in a ToolStrip. So the items you add to a ToolStrip are not controls as the other ones.

Let's look at it from the documentation, that is a very good tool to understand a lot of things, such as what is happening here.

If you look at the documentation for the class of any of the "normal" controls, such as the Button (, you see in the Inheritance Hierarchy that they all inherits, directly or indirectly, from the Control class. You can thus handle them through a Control variable as you do when you assign them to your ctlType, and work with properties and methods that are common to all controls. This capacity of handling an object through a class from which it inherits is called polymorphism.

If you look at the documentation for the ToolStripStatus class (, you see in the Inheritance Hierarchy that it does not inherit from Control. In such a case, there is no polymorphism, and you cannot assign it to a variable of type Control. You will have to treat your ToolStripStatus through something else, either a ToolStripStatus variable, or if you are working with different ToolStrip controls, through a ToolStripItem variable, since this is the common class from which all ToolStrip controls inherits.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlakeMcKennaAuthor Commented:
So when my ctlType is equal to a StatusStrip control...there is no way for me to loop thru this control to check for any occurrence of the ToolStripStatusLabel and change the properties?
Jacques Bourgeois (James Burger)PresidentCommented:
No, because ctlType is a Control and the ToolStripStatusLabel is not a Control although we see it and use it as one.
BlakeMcKennaAuthor Commented:
That's fine, I tried what you suggested in your first post and got it working! Thanks for your help James!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.