rmPaintBox.cc  
 

A Custom PaintBox Control

 


The PaintBox control is a very powerful, but underused control. Most developers consider that it is just too much work. Why is this ?

The stock control comes with little documentation, no sample code, and every single painting API call has to be prototyped by the developer.

Having done quite a bit of work over the years with PaintBox controls, I finally realised that for each control being worked upon I was pulling in API prototypes from previous controls, and very often duplicating much of the work I had already done.

With these factors in mind, the penny finally dropped that what I needed was a custom base class from which to subclass any other PaintBox based control. All that would be needed in future would be to add any new painting functionality as required.

In addition any other developer wanting to do PaintBox development work would benefit from the head start that this base class provides.

If the stock PaintBox class had shipped with all this functionality built in from the start, I wonder if more developers would have developed more controls with it over the years as a result.

So this control will always be "work in progress" and any API prototypes or painting functions that are not currently included would be welcomed as contributions.

In order to provide a little basic sample painting code, the form seen above is included. This demonstrates the general approach that should be taken with any subclass, where conditional painting is dictated by the values of custom properties of the subclass, and any outside influence on painting is handled by updating those custom properties which are then evaluated at paint time.

This form is only a crude basic sample. It is possible to achieve very sophisticated end results, and this base class should take much of the "grunt work" out of this task. As with anything of this nature, a little artistic and graphical design talent goes a long way in complementing coding skills.

For a more sophisticated sample of what can be achieved, take a look at rmXPTabBook.cc which is a fake notebook control with XP style graphics and the ability to place a bitmap on the tabs.

Recent additions to this control bring XP theme awareness so that not only can you conditionally code to paint your custom control to match the current XP theme colour, but such a control will even respond if the XP theme colour is changed mid session.

Any feedback on, or any contributions to this class will be welcomed.

See rmPaintBox.wfm for sample usage and code.