12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

278 Day 8<br />

NOTE<br />

Modify<strong>in</strong>g the Enabled property for a panel component has additional<br />

implications. Panels are often used as conta<strong>in</strong>ers for other controls.<br />

Therefore, they become the parents of the controls that are placed<br />

with<strong>in</strong> them. If you disable a panel, the components on the panel will<br />

not show as disabled, but will not function because their parent (the<br />

panel) is disabled.<br />

Although components can be disabled at design time, enabl<strong>in</strong>g and disabl<strong>in</strong>g components<br />

is someth<strong>in</strong>g that is usually done at runtime. Menu items, for <strong>in</strong>stance, should be enabled or<br />

disabled accord<strong>in</strong>g to whether they apply at a given time. The same is true of buttons. There<br />

are a variety of reasons why you might want to disable other types of controls as well.<br />

To disable a component at runtime, just assign false to its Enabled property, and to enable<br />

a component assign true to Enabled. The follow<strong>in</strong>g code snippet enables or disables a menu<br />

item based on some condition:<br />

if (saveEnabled) FileSave->Enabled = true;<br />

else FileSave->Enabled = false;<br />

This process is often referred to as command enabl<strong>in</strong>g and is an important part of a<br />

professional-look<strong>in</strong>g W<strong>in</strong>dows program.<br />

The Font Property<br />

The Font property is a major property and therefore needs to be <strong>in</strong>cluded here, but there is<br />

not a lot that needs to be said about it. The Font property is an <strong>in</strong>stance of the TFont class,<br />

and as such has its own properties. You can set the Font properties by double-click<strong>in</strong>g on the<br />

font name <strong>in</strong> the Object Inspector (which will expand the Font node and show the Font<br />

properties) or by <strong>in</strong>vok<strong>in</strong>g the Font dialog box. (The Font dialog box is discussed <strong>in</strong> more<br />

detail later <strong>in</strong> the chapter <strong>in</strong> the section “The Font Dialog Box.”) Figure 8.2 shows the Object<br />

Inspector with the Font property node expanded to reveal the TFont properties.<br />

The Color property sets the color of the font, and the Name property allows you to choose the<br />

typeface for the font.<br />

The Height and Size properties of TFont deserve special mention. The Height property is used<br />

to specify the height of the font <strong>in</strong> pixels, whereas the Size property is used to specify the<br />

height of the font <strong>in</strong> po<strong>in</strong>ts. When you change one of these properties, the other will change<br />

automatically. The Height is often specified as a negative number. Refer to the onl<strong>in</strong>e help<br />

for TFont for an explanation of why this is the case.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!