The magazine of the Melbourne PC User Group

Seeing the Basics: Did you know? (Part 2)
Tony Stevenson

More interesting facts about VB

Last month's column looked at some different and interesting aspects of the Visual Basic language, presented under the general title of Did You Know? It continues this month with Part 2.

Light controls

Did you know: The shape, line, image, and label controls use less Windows resources than the typical Visual Basic custom control. Subsequently, they are often referred to as light controls. In fact, they're not even regarded as being real windows.

However, the advantage of needing fewer resources is offset by these controls having lesser capabilities. For instance, these light controls are not able to receive the focus when an application is running.

To see for yourself, start a new standard EXE project, and then add a command button, a label, and another command button, in that order, to the project's solitary form. It doesn't matter where these controls are positioned on the form. Now run the program and press the Tab key half a dozen or so times.

You can tell when each of the command buttons gets the focus because a dotted line appears just inside the boundary of the button. Notice that the label control misses out completely on getting the focus.

There are another couple of ways, apart from the Tab key, in which controls can get the focus.

The first way is using the mouse. Simply click on one of the command buttons using the left mouse button to cause the dotted line to appear. Again, notice that there is no change in the appearance of the label control when you click on it.

Secondly, getting focus can be achieved using VB code. Being able to set the focus programmatically on a control has some real advantages when running an application. For example, you can set the focus onto a particular text box to indicate to users that you want them to enter some characters. You can even force people to enter characters, and stop them from carrying out any other activities unless they do so, for example, when a password is required in an application. Remember, however, to give them an option to quit.

Alternatively, you can set the focus to, say, a command button, to point out to users that this is the button that will initiate the next action to occur within an application.

To see a quick demonstration of how this works, add the following brief snippets of code to the project we have already started.

Code the click event of the first command button, as it appears in Listing 1.

Listing 1

Private Sub Command1_Click ()
Command2.SetFocus
End Sub


And for the click event of the second command button, add a Message box statement which will force the display of an appropriate message, as shown in Listing 2.

Listing 2

Privare SubCommand2_Click ()
MsgBox "Action initiated from Command Button 2"
End Sub


Now run the application. Notice how the focus is on the first command button, that is, a dotted line appears within its boundary. Click this command button with your mouse, or alternatively, just press Enter. Notice how the focus has shifted to the second command button. Press the Enter key again to force the message, which we have just coded, to appear.

Setting and re-setting the focus of controls programmatically like this within a VB application can be a powerful way of letting your users interact more satisfactorily with it.

Form and Control colours

Did you know: There are at least four colour properties you can manipulate with forms and most of the other Visual Basic and third-party controls you use. ("Third-party controls" is a generic term used to refer collectively to those controls you purchase from software manufacturers to extend further the functionality already available with Visual Basic.)

These four colour properties are the BackColor, BorderColor, ForeColor, and the FillColor properties.

The BackColor property is used to set the background colour of either a form or a control.

The BorderColor property, as suggested by its name, is used to set the colour of the border (or boundary) of a control.

The ForeColor property is the colour used for either the text or graphics drawn (painted) on a form or a control.

And finally, the FillColor property is used to set up the colour for "filling" in shapes. It is also commonly used as the colour for filling in circles and boxes which have been drawn using VB's circle and line graphics methods.

To see the sort of effect setting these properties can have, start a standard project, add a collection of different controls to a form, and just start experimenting.

Colours are a powerful aspect of a Windows interface. However, too many colours, or the wrong choice of colour, or a mixture of colours that clash, can not only make an interface ugly, it can, in extreme cases, make it difficult to work with.

Here are just a few of the many issues to be considered when using colour within your VB applications.

  • The appreciation of a particular colour scheme is very much based on personal taste. So unless you're developing your application for just one person, be aware that colours which may appeal to one person may not be appreciated by a different user
  • You don't have to use colours to design and build quality graphical user interfaces (GUIs). In fact, some of the most effective ones just use the colour "grey", with "black" used for text
  • Colours can significantly affect how users perceive your application. For example, some colours are extremely difficult to read, whilst others can be very tiring to look at, and so on
  • Regardless of whatever colours you choose to use, be consistent with your use of them. For example, if you use a specific colour for error conditions, ensure that you always use that same colour for errors (and no other colour) throughout your application
  • Did you know that approximately 6 percent of the population is afflicted by colour blindness? Take this into consideration, and always have a secondary means of highlighting the different aspects of your interface. Never just rely on colour by itself.
S o as you can see, using colours successfully within applications is a complex undertaking.

If you're interested in finding out more, check with your favourite computer book shop about what graphical user interface design and evaluation books they have in stock (or e-mail me).

More interesting facts about VB

Next month we will continue with part three of Did You Know?

Reprinted from the March 1998 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]