Access Cookbook - Ken Getz [194]
You can extend the animated button technique in several directions:
By including multiple hidden buttons on your form, you can create a three-state button with a picture that changes when it is the currently selected button as well as when it is pushed.
You can modify the event procedure to allow for animated buttons with more or less than eight frames of animation. To do this, break up the table of frames into two related tables, one holding the name of the animation and the number of frames, and the other holding the actual picture data.
The sample form shows how to use two arrays and some additional code to have two continuously animated buttons on the same form. You might generalize this code as well, but watch out—forms with too many animated buttons look busy.
If you open the sample form and hold down any button, you'll see that the animations stop for as long as you keep the button depressed. This prevents the form's Timer events from firing.
TIP
To see the effects of the MouseDown event, you must call the form's Repaint method, which tells Access to complete any pending screen updates. On the other hand, you don't need to do this in the MouseUp event (although it doesn't hurt if you do)—Access automatically repaints the screen after a MouseUp event.
9.8. Create an Expanding Dialog
Problem
You have a dialog with a lot of options, most of which are needed only in specific situations. You'd like to create this form as an expanding dialog, similar to forms that have an Advanced button revealing more options. How can you do this with your own form?
Technique
You can make a hidden section of the form become visible at runtime, and use the Window | Size to Fit Form command to force the form to expand to fit its new dimensions. This solution shows you how to create this type of form using an expanding form footer. You'll also learn how to minimize screen flashing while resizing the form by manipulating the form's Painting property.
Follow these steps to create your own expanding dialog form:
Create a new form. To make the form look like a dialog, set the properties of the form as shown in Table 9-6. Some of these property settings are optional, since the expanding technique will work with non-dialog forms too. The settings for the DefaultView and AutoResize properties are required.
Table 9-6. Property settings for a dialog form
Property
Value
DefaultView
Single Form
ScrollBars
Neither
RecordSelectors
No
NavigationButtons
No
AutoResize
Yes
AutoCenter
Yes
PopUp
Yes
Modal
Yes
BorderStyle
Dialog
MinMaxButtons
None
Select View → Form Header/Footer to add a footer section to the form. Set the Visible property of the footer section to No. Because you're interested in only the footer section, you may wish to grab the bar separating the detail and header sections and drag it up so the header section has a height of zero.
Partition the controls on your form into two groups: those you wish to display at all times, and those you wish to display only when the form is in the advanced (expanded) state. Place the first set of controls in the form's detail section; place the second set of controls in the footer section.
Add a button named cmdExpand with the caption "Advanced >>" to the detail section of the form. Create an event procedure attached to the Click event of the button. (If you're unsure of how to do this, see How Do I Create an Event Procedure? in the the preface of this book.) Add the following code to the event procedure (or copy the code from the frmExpandingDialog form's module in 09-08.MDB):
Private Sub cmdExpand_Click( )
Dim sct As Section
Dim blnExpanded As Boolean
Const acbFirstBasicCtl = "txtFirstName"
Const acbFirstAdvancedCtl = "txtOldPW"
Set sct = Me.Section(acFooter)
' Keep track of the state of the form when first called.
blnExpanded = sct.Visible
' If the form is in nonexpanded