PC Differences

From a user interface standpoint, extra thought is required when you're writing a program that is designed to run on a PC other than your own. Visual Basic programs run on Windows 95, Windows 98, or Windows NT (not to mention Windows CE). Each of these operating systems is different, and each PC running them can be set up differently.

If you want to know programmatically which operating system your
user is running, check out the GetVersionEx API call or the SysInfo
custom control.

In addition, the Windows operating system leaves a lot of room for user customization. One of the most noticeable differences may be screen resolution. If you go into the Windows Display Control Panel, you may notice that several options for screen size are available. As a developer and owner of a 21-inch monitor, I like to leave my PC at 1280X1024, which allows me to place a lot on the screen at once. However, most of your end users are likely to be operating at a lower resolution, say 640X480. The easiest solution to this problem is to design your forms for the minimum 640X480 resolution. The users at that resolution will see your application fill up the whole screen, while users at higher resolutions will have extra desktop space to open other windows. But what happens when the user adjusts the size of your form with the mouse? If you do not write code to handle this situation, users at higher resolutions could get unpleasant results, as in Figure 18.7.

Figure 18.7

If you do not respond to users resizing your form, wasted space appears.

In addition, a user can make a form smaller, obscuring some controls. However, if your form is simple enough, you may be able to add some code to the form’s Resize event to make it resolution independent. By looking at the Height and Width properties of each control and comparing them to the form’s height and width, you can easily add code so that controls will maintain their relative positions when users resize your form. The following code adjusts the sizes of a list box and two command buttons so that their sizes will change with the form:

Private Sub Form_Resize()
    If Me.Height <= 1365 Then Exit Sub
    lstMain.Height = Me.Height - 1365
    lstMain.Width = Me.Width - 420
    cmdOK.Top = lstMain.Height + 360
    cmdOK.Left = lstMain.Width - cmdOK.Width
    cmdCancel.Top = cmdOK.Top
    cmdCancel.Left = cmdOK.Left - cmdCancel.Width - 120
End Sub

For an even better form, change the font size of your controls
as the form size changes.

Note that the first line of code in the Resize event exits
the event procedure if the form height becomes too small because
an error would occur if a negative value were assigned.

You also can find third-party controls that can be used to add
resolution independence to your applications.

Another customization that can adversely affect your program is the Regional Settings Control Panel, pictured in Figure 18.8. This screen allows users to set their own currency and date format, among other things. If you use these predefined formats in your program, make sure that your variables, database fields, and calculations can handle them.

Figure 18.8

Make sure your program is prepared to handle changes users make in the Regional Settings Control Panel.

Top Home