One of the features of our Access JumpStart application template is a form resizing class:
This VBA class, HAL_FormResizeCls
, is designed to handle the resizing of forms and their controls in Microsoft Access. Here’s a summary of its functionality and how it works:
Purpose
The class processes form resizing, ensuring that controls on the form are rescaled and repositioned appropriately when the form size changes. This is particularly useful for maintaining a consistent layout and appearance across different screen sizes and resolutions.
Key Components
- Enums and Constants:
CtlPositionTag
: Enum for storing/retrieving control positioning data.frScaleMode
: Enum for different scaling modes (automatic by width, automatic by height, fixed).- Constants like
FrmHeightMax
andFrmWidthMax
define the maximum dimensions for the form.
- Properties:
DebugON
: Controls whether debug messages are printed.FixedScale
: Sets or gets the fixed scaling factor.TimedResize
: Enables or disables timed resizing.TimerInterval
: Sets or gets the timer interval for resizing.DefaultAspectRatio
: Sets or gets the default aspect ratio.ScaleType
: Sets or gets the current scaling mode.DoSubForms
: Enables or disables scaling for subforms.ResizeInProgress
: Indicates if a resize operation is in progress.
- Methods:
SaveControlPositions
: Saves the original positions and sizes of controls.RescaleControlPositions
: Main method to rescale controls based on the current scaling mode.SetSizeOptions
: Toggles through different resize scale-set algorithms.TimerEvent
: Handles the timer event for resizing.RescaleControlPositions_Main
: Core logic for rescaling controls on the main form.RescaleControlPositions_Sub
: Handles rescaling for subforms.RescaleControlsOnForm
: Rescales and repositions each control on the form.
How It Works
- Initialization:
- The class is initialized with default properties, such as enabling the timer switch, setting the timer interval, and defining the default aspect ratio.
- Saving Control Positions:
SaveControlPositions
method is called to store the original positions and sizes of all controls on the form. This information is saved in theTag
property of each control.
- Rescaling Controls:
- When the form is resized, the
RescaleControlPositions
method is triggered. If timed resizing is enabled, it sets a timer to delay the actual resizing. - The
RescaleControlPositions_Main
method calculates the new scaling factor based on the current scaling mode and resizes the form and its controls accordingly. - The
RescaleControlsOnForm
method iterates through each control, adjusting its size and position based on the scaling factor.
- When the form is resized, the
- Handling Subforms:
- If subform scaling is enabled, the
RescaleControlPositions_Sub
method is called recursively to rescale controls within subforms.
- If subform scaling is enabled, the
- Debugging and Error Handling:
- The class includes debug messages and error handling to assist with troubleshooting and ensure smooth operation.
Currently Known Issues:
Controls That Might Not Work Well
- Custom ActiveX Controls:
- Custom ActiveX controls or third-party controls might not respond correctly to the resizing logic, as they may have unique properties or behaviors that aren’t accounted for in the class.
- Bound Object Frames:
- Controls like Bound Object Frames, which display OLE objects, might not resize properly because their content can vary significantly in size and aspect ratio.
- Charts and Graphs:
- Microsoft Access charts and graphs can be complex to resize dynamically, especially if they have detailed formatting or data-bound properties.
- Web Browser Controls:
- Web Browser controls might not resize as expected due to their dependency on external content and rendering engines.
- Subreports:
- While the class handles subforms, subreports might not be resized correctly, especially if they are embedded within other controls or have complex layouts.
Scenarios That Might Cause Issues
- Nested Controls:
- Controls nested within other controls (e.g., a control within a tab control) might not resize correctly if the parent control’s resizing logic isn’t properly handled.
- Conditional Formatting:
- Controls with extensive conditional formatting or dynamic visibility settings might not resize as expected, as the class might not account for all possible states.
- Complex Layouts:
- Forms with very complex layouts, including multiple sections and overlapping controls, might experience issues with resizing and repositioning.
- VBA Code using the Tag property of controls:
- Forms with existing VBA code using the Tag property of controls will conflict with the current version of this class.