Session #12
OwnerDraw TechniquesSuppose that a visual component doesn't display information exactly the way you want it to? For example, in a tree view control (TTreeView), you can specify the properties of the font (TFont) used for the text. However, this property applies to the entire tree view. You can't specify the font that is used for each individual line in the tree view. Well, this is where the concept of "OwnerDraw" comes in. Basically, it means that the programmer takes control of drawing each item in the control, instead of letting the control do it automatically. This is actually a fairly easy thing to do, depending of course on what you actually want to do.
In addition to changing the font properties (name, size, color, etc.) you can do things like wordwrap the lines in the tree view, or draw bitmaps within the text. Pretty much anything. Again, the more "radical" you want to get, the more work it is. Most of the time you will rarely need to draw things yourself. But, when you do, OwnerDraw is the mechanism.
This application shows how to use the OwnerDraw style to display each line in a list box in a different font and/or color. It also shows how to draw each panel in the status bar in a different way. There isn't a lot of code or a lot of output displayed here, but the OwnerDraw technique is a very powerful concept that can come in handy when you need it.