The magazine of the Melbourne PC User Group

Seeing the Basics: VB 6.0
More "Did you know ....?"

Tony Stevenson

Choosing the right colour scheme

Just one of the many benefits of Visual Basic is that it's often a straight-forward exercise to change the appearance of an application's interface by altering the values of properties. For example, to change the background colour of a form, just alter the contents of the form's BackColor property to the desired value.

However, it is preferable to stick with the standard Windows colours when designing your Visual Basic applications. The reason is that a lot of users like to alter the appearance of their desktop using the functionality available in the Windows Control Panel. And, when they do so, there is an increased likelihood that your unique colour scheme will clash strongly, making your application look gaudy and unprofessional.

Another important reason for complying with the standard Windows settings is that an unwise selection of colours may prevent your application from being awarded the officially recognised, and highly valued, "Designed for Windows" logo. Not having this logo can have a significant, negative impact on any future sales of your software.

Note to new Windows users: to alter the appearance of your desktop in Windows 9x, click "Start" on the Taskbar, then "Settings", followed by "Control Panel", and when the "Control Panel" dialogue appears, double click the "Display" icon. Next, on the "Display Properties" dialogue, click the "Appearance" tab, and start experimenting with different colour schemes until you find one you prefer.

Status in the Windows taskbar

Normally, when your newly completed application is running, it will appear as an active program in the Windows 9x Taskbar. For example, with a single form application, it will be depicted on the Taskbar as a small Visual Basic icon with the caption of the form written next to it.

However, there might be those odd occasions when you don't want the running application to be visible to users in the Taskbar. Achieving this in a Visual Basic 6.0 program is easy--simply alter the form's "ShowInTaskBar" property to a value of "False".

A word of warning: it's not possible to programmatically control whether or not the running application appears in the Taskbar using this property. For example, if you were to add this code
ShowInTaskBar = False

to the "Load" event of the form Visual Basic would generate a compile error. The reason is that the "ShowInTaskBar" property is "read-only" at run time.

Adding graphics to Command Buttons

A quick way of adding a professional look to your program's interface is to add graphics to its command buttons. To do so, all that's required is to set just two properties. Firstly, change the command button's "Style" property from the default setting of "Standard" to "Graphical", and then point the button's "Picture" property to the graphics file of your choice. It's as easy as that.

Did you know that for additional graphical effects with command buttons you can also use the "DisabledPicture" and "DownPicture" properties? As their names suggest, the "DisabledPicture" is used to display an associated graphic whenever the button is disabled, that is, it doesn't respond to any user interaction, for example, clicking it with a mouse will be ignored. A command button is easily disabled in code by setting its "Enabled" property to "False".

In a similar fashion, the "DownPicture" property is used to display the chosen graphic whenever the command button is clicked down with the mouse.

Note: when using the "DisabledPicture" and "DownPicture" properties make sure that the "Style" property is also set to "Graphical".

Limiting user input

Most of the Visual Basic applications that you'll write will require users to input some information via text box controls, for example, a name, address, telephone number, and so on.

An easy way to limit the number of characters that can be entered into any one of these text boxes is to take advantage of the text box control's "MaxLength" property. Simply set it to the desired length of the field.

However, it's also a good idea to somehow notify users of this pre-set limit, otherwise casual users of your application will be mystified as to why your program is no longer accepting input. One option is to use the label associated with a text box to indicate the maximum number of characters that can be entered, for example, "Surname (Max 25 chars)".

Note, too, that in Visual Basic 6.0, if you want to use text boxes just to display information, you can prevent users from tampering with the contents by setting a text box's "Locked" property to "True". In previous versions of Visual Basic, the same effect was achieved using the "ReadOnly" property but this is no longer available.

Access keys

For users of your applications who prefer the keyboard to their mouse, you can set up access (or hot) keys, to help them navigate around the interface more easily. An access key is instantly recognisable because it is underlined, for example, the caption of a command button in a running program might appear as "Click me". However, in Visual Basic design mode, the "Caption" property for this command button contains the letters "&Click me" in order to set up the letter "C" as an access key.

To activate an access key when a program is running, press the Alt key on the keyboard and hold it down while simultaneously pressing the designated key. An access key can be used to open a menu, carry out a command, select an object, and so on.

But what happens if you want an actual ampersand character to appear in the caption of a label? The solution is to use the label's "UseMnemonic" property. By setting this property to "False", an "&" will appear in the caption instead of an underline.

Reprinted from the April 1999 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]