Re: Creating Forms with fixed set of controls

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Fri, 13 Jul 2007 12:19:58 -0700, Doc John <no <"email>"> wrote:

[...]
So I was thinking that, somehow, I could create a Base Form so that all
these Form would inherit from it. The same way they'll inherit the Form
backcolor when I change the background, maybe there's a way that all buttons
can inherit from a "base button".

If the button itself exists as an instance on the base form, then that would work. All the forms inheriting the base form would also inherit the base button _instance_ and that _instance_ would have the green background you specify in the base form.

The only way to make a base button _class_ that all the other buttons in the project inherit would be to go ahead and make that inherited button class, and then change all of the button instances in all of the forms to use that class instead of the Button class. A simple search-and-replace might actually accomplish that, but it's an even more broad change than the already-broad suggestion of changing all your forms to derive from a single base form.

An alternative to the inheriting of a form with a button instance, or of changing your buttons to use a new derived button class, would be to make the base form as suggested before, but instead of putting the button instance in the form itself for the inheriting classes to inherit, override the OnLoad() method in the base form class, enumerate all your controls in the form, and for every button change the background color to whatever you want.

I am not aware of a general-purpose way that you can do something simple and have all of your controls draw in a different color, for example. As of Windows XP, there's an idea called "visual styles", but AFAIK this is controlled by the OS; you can take advantage of it to use the "current style" for your UI, but your application cannot override the current visual style by automatically using a different visual style for rendering.

Pete
.


Quantcast