VB.NET - Subclassing exisiting controls

Hi there,

I am quite new to VB.NET, moving over from Visual Foxpro.  In foxpro it was possible to subclass all of the standard windows controls in a class lbrary and then use the subclassed controls to build your forms.

The main benefit is that you can add functionality to the standard controls and adjust there appearance in the subclassed control which would then filter down to the controls throughout your application.

I have built a class library in VB.NET and subclasses all of the controls using the standard...

Public Class myTextBox
 Inherits TextBox

End Class

This works fine and I can add the class library dll to the toolbar - great.  The only problem is, when I alter a control in the class library (say changing a font for example) - the change isnt reflected in the forms that use the control.  In order for this to work I have to remove the controls and add them again!

Am I missing something here?  Has anyone any examples of a control library class that I can look at?

I would really appreciate your help as im getting more and more irritated by some of the .NET functionality! (I wont mention transparent controls!!)

Kind Regards

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.

I know exactly what you are talking about and I had the same thing happen to me too.

 All you have to do is update the reference to the DLL....allow me to explain in more detail. ;)  

You have a dll called myTextBox.DLL for example.  

What's happening is when you update your Control Library you are changing myTextBox.DLL but your project is still referencing the OLD DLL.  

All you really have to do is when you are making changes to your control library make sure to rebuild the dll.  

Now in your project you can just expand your references folder in the solution explorer, right click on your myTextBox.DLL and click "remove" then right click again on the References folder and click on "Add Reference", find your Control Library and select it.  

I know this is a major pain but I don't know of any other way to do this.  

You don't have to actually REMOVE the controls from the form you just have to update the Reference.  

This is somewhat difficult to explain without giving you several chapters here, so if you want you can email me at tmyers2578@hotmail.com if you need a more concise explaination.

Hope I helped restore some faith in VB.NET ;)


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
ah7386Author Commented:
Thanks for the post - it helped me solve my problem.  If I remember correctly there is an option in the properties of the reference (mycontrols.dll for example) you can tell .NET not to copy the control to the application directory - i think this will force VB to update the reference automatically - I cant remember the exact details as im not at my work PC at the moment.

Anyhow - many thanks for your detailed response.

PS - when your altering fonts etc.  Which event do you use to put your:

 font = new font("Tahoma")

code in? - the NEW or the OnCreateControl event?


I'm not sure about that one...The thing I like about creating my own controls is that I can make my own properties and then just set them from the properties window....Sorry

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
.NET Programming

From novice to tech pro — start learning today.