Form Color Class
Form Color Class
CLASS MODULE
FORMCOLOR CLASS
ADD COLOR AND GLOW EFFECTS TO USER FORMS
OK
Installing App
Requirements Installing Running
This demo requires MS Excel 2007® 1. Download FormColorClass.zip 1. Open the folder
or later. VBA (macros) must be enabled. 2. Once downloaded, right click on the 2. Double click Forms.xls
zip file and use option Extract All 3. If Protected View displays click
3. Make note of folder’s path. Enable Editing.
Routine Description
Launch This is the main routine tied to the form button. For more information
on this see Code
modGeneral This is BXL’s general purpose library of routines common to all BXL apps. Because this is a general
purpose library, please see the module for documentation on each routine. Only two are used in this
project. modGeneral.DspErrMsg and modGeneral.Color()
NOTE! This module is required in your projects that use clsForm.
Routine Description
Color This function stores and returns colors for various workbook elements.
DspErrMsg For more on BXL error handling see BXL Error Handling
Forms
Component Description
frmTest This a sample selection form to demonstrate clsForm. It is important
to note this form has no color added and no functions to add color. It
is a normal form. All coloring is added by clsForm.
NOTE! This form is NOT needed in your projects that use clsForm.
Property Description
UserForm This handles a bit of a quirk with Excel’s user forms. UserForms as a
UserForm object type exposes events we need to turn off button glowing
effects. But UserForm as a UserForm object type does not expose
properties such as top, width, etc. UserForm as a generic Object object
type does.
For more information on this see Code
Frame This control, like the userform itself, is control container. When the
mouse hovers over a control container, all buttons and images in the
control container must have their glow effects turned off.
Image This control can glow when the mouse hovers over it if its picture has
transparent portions.
Multipage This control, like the userform itself, is control container. When the
mouse hovers over a control container, all buttons and images in the
control container must have their glow effects turned off.
CommandButton This control can glow when the mouse hovers over it.
Event Description
Class_Terminate Handles housekeeping when the class goes out of scope.
oMsForm_MouseMove Turns off button glow when mouse hovers over the form’s surface
oFrame_MouseMove Turns off button glow when mouse hovers over a frame’s surface
oMltPag_MouseMove Turns off button glow when mouse hovers over a multipage’s surface
Routine Description
Setup Initializes backgrounds, fonts and positions.
modMain.Launch
This routine instantiates clsForm, links it to frmTest, and displays frmTest. It is just four lines of code which is all we need to link
clsForm to any userform we have.
We require a variable to Sub Launch()
instantiate our class and keep it in Static FormClass As clsForm
memory. As long as the variable
exists in memory, our class
continues functioning.
Static is a keyword that
declares a variable that doesn’t
get destroyed when a subroutine
ends; thus, we can use a static
variable to keep our class In
memory as long as our project is
running.
New creates an instance of Set FormClass = New clsForm
our class which we assign to our
static variable for safe keeping.
We assign our user form Set FormClass.UserForm = frmTest
frmTest to our class UserForm
property. At this point, our class
will now handle frmTest’s events
for us.
All that remains to do is show frmTest.Show False
our user form. End Sub
' Declarations
Const cRoutine As String = ".Set UserForm"
End Property
clsForm.Setup
This initializes all control colors, creates instance of this class object for each control, and positions the userform in the center of
the screen.
This code block is a standard Private Function Setup(ByVal oForm As Object) As Boolean
BXL documentation block. For ' Description:Set backgrounds, fonts, and position
more on BXL standards see BXL ' Inputs: oForm User Form (as Object for Properties)
Coding Best Practices ' Outputs: Me Success/Failure
' Requisites: Classes clsCmd
' Example: ?Setup(oForm)
End Function