Programmer's Perspective ] Ins and Outs ] WhereCode ] Typology ] Alphabetic Information ] Arrays and Looping ] Builtins ] Randomization and Simulation ] [ Controls ] Creating and Using Files ] Errors ] Key Codes ] Drive Office With VB ]

 

 


Control Issues

The components that do things are found in the Toolbox to the left on the Design screen.  Each has a special purpose.  The Toolbox is set up rather sparsely by default.  Other components may be added through the Projects Menu by clicking on Components...  The controls I add routinely are the Windows Common Controls, the Rich Textbox, the Microsoft Hierarchical FlexGrid Control (if I want to display a grid or table), and the Microsoft Chart Control (if I want to show a graph). 

To use a control, drag its icon from the Toolbox to the form.  You can regulate its size and location with the mouse or with properties (Left, Top, Height, Width) shown in the Properties Window.  Each control has its own set of properties; these depend on the control's purpose.  Many properties can be set at design time by changing the defaults shown in the Properties Window.  All properties can be set or reset through code; the Form_Load() subroutine is a convenient place to set the properties that govern the initial appearance of the control.  Controls also have events assigned to them, such as the Click event.  The Click event triggers a Subroutine when the user clicks on the control.  

A control may be disabled (grayed out, but visible) by setting its Enabled property to False.  A control may be hidden periodically during program execution (it will always appear in Design Mode) by setting its Visible property to False.

The Picture Box and Image controls may be used to display a picture that is stored as a file (use the Picture property to embed the file when in design mode).  The Image control uses fewer resources, but the advantage of the Picture Box is that it has more properties.  The Picture Box can serve as a container for other controls, and you can also print to it.  An annoying VB feature is that if you want to assign a picture to the control during program execution, you must use the LoadPicture method rather than the Picture property.  That is, the picture file is assigned with a statement such as Image1.Picture = LoadPicture ("a:myface.bmp").  The file names are strings. To clear out the picture, use the LoadPicture function with an empty parenthesis [Picture2.Picture = LoadPicture ()].

The Frame control also can serve as a container for other controls, usually for a set of Radio button (known formally as Option Buttons, discussed below) controls.  The frame organizes the display nicely, and also has the programming advantage that you can make all of the contained controls Visible or Enabled in one step by setting the Frame's property. 

Resizing Controls

When the size of the form is changed during program execution, the size of the controls and their text ought to change too.  But VB doesn't do that automatically; you have to insert code to bring about the changes.  Fortunately, the code is pretty simple.      

The Chart Control

The chart control allows you to embed all types of graphs within your program.  The control has a lot of properties, and is not easy to use.  But the results can be spectacular.

Option Buttons

Option buttons provide a mechanism for posing choices to the user.  They are ideal for yes-no questions as well as for Likert scales.  Some hints are provided to help you make them behave properly.

The Timer Control

The timer control, along with some built-in functions related to time, allow you to control stimulus presentation and to record response times.

The List Box and Combo Box Controls

The list box control is used to present a complete list of choices, while the combo box control is similar but allows the user to enter another choice if none of the program's offerings is desired.