The Frame Control

The Frame control groups ActiveX controls on a form. The ActiveX controls grouped within a Frame control may be related by content, or in the case of Option Button controls, be made mutually exclusive. The properties of the Frame control are seldom referenced in code. The Name and Caption properties along with a couple of appearance properties (BorderStyle, Font, etc.) are typically set at Design Time.

You will seldom (if ever) programmatically access the Frame control. The Frame control organizes or groups controls on a form for aesthetic appearance; in the case of Option Button controls, behavior. A sample form using two Frame controls, each grouping a set of Option Button controls, is shown in Figure 6.7. A Scroll Bar and two Label controls have also been added to the UserForm.

The purpose of the form shown in Figure 6.7 is to give the user a selection between different font types, sizes, and colors. The result of the user's selections is displayed in the Label control at the bottom of the form. The font size of the text in this Label control is adjusted by the Scroll Bar control (the value of which is displayed in the adjacent Label control). The Frame controls group the Option Button controls by content and make each set mutually exclusive. Without at least one Frame control, the user would only be allowed to select one of the eight Option Buttons.

I set the usual properties of these controls at Design Time. This includes the Name, Caption, size, and appearance properties (fonts, colors, borders, and so on) of each control. The Min and Max properties of the Scroll Bar control were set to 6 and 40, respectively.

The code for this demonstration program is contained entirely in event procedures of the UserForm object and ActiveX controls. The Initialize() event of the UserForm object sets the initial Caption property of the Label control that displays the font size (in pts), and the Click() event procedure of each Option Button control sets the ForeColor and Font properties of the Label control at the bottom of the form. Finally, the Change() event of the Scroll Bar control adjusts the font size of the Label control at the bottom of the form and writes this size to the adjacent Label control. The entire program entered into the form module follows:

Option Explicit

Private Sub UserForm_Initialize()

lblFontSize.Caption = scrFontsize.Value & " pt" End Sub

Private Sub optBlack_Click()

lblResult.ForeColor = vbBlack End Sub

Private Sub optBlue_Click()

lblResult.ForeColor = vbBlue

End Sub

Private Sub optGreen_Click()

IblResult.ForeColor = vbGreen End Sub

Private Sub optOrange_Click()

lblResult.ForeColor = RGB(255, 125, 0) End Sub

Private Sub optRed_Click()

lblResult.ForeColor = vbRed End Sub

Private Sub optArial_Click() lblResult.Font = "Arial" End Sub

Private Sub optSans_Click()

lblResult.Font = "MS Sans Serif" End Sub

Private Sub optTimes_Click()

lblResult.Font = "Times New Roman" End Sub

Private Sub scrFontsize_Change()

lblResult.Font.Size = scrFontsize.Value lblFontSize.Caption = scrFontsize.Value & " pt" End Sub

Note that, when possible, I use VBA color constants to set the ForeColor property of the Label control; however, orange is not a defined constant, so I call VBA's RGB() function to set the red, green, and blue components (integers between 0 and 255) to return the long integer representing orange.

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Post a comment