Version 1.1 Approx 0.8 MB (zipped) First Published 19 Mar 2024 Last Updated 10 Oct 2024
My Attention Seeking example database demonstrates several ways of focusing users' attention on a specific form on the screen with minimal effort.
These include scrolling or flashing text, blurring, dimming or removing the background.
This article discusses how to dim or remove the background by changing its opacity. For example, in the screenshot below, the backgound has an opacity of 80%. Background objects cannot be clicked.
I have used this approach in several of my example apps such as Application Tips and Move / Resize Selected Columns
However, until now I have not explained how it works in any detail.
The dimmimg effect is achieved using a background form, frmDimmer. The highlighted form must be a popup and requires just two lines of code.
Download
Click to download:
Highlight Entire Form v1.1 ACCDB file Approx 0.8 MB (zipped)
Download and unblock the zip file. For more details, see my article: Unblock downloaded files by removing the Mark of the Web
Unzip and save the ACCDB file to a trusted location.
How the Example App works
The app opens to a startup form. This includes a combo box which can be used to adjust the opacity value
When you click the Open Popup Form button, the background is automatically dimmed:
This is achieved by overlaying the entire screen with a form frmDimmer which applies the specified opacity. In this case 80%.
The highlighted form MUST be a popup so that is is independent of the application interface and therefore unaffected by the dimming effect.
Just one line of code is required in the Form_Load event of the highlighted form: Form_frmDimmer.DoDim Me
When the highlighted form is closed, the dimming effect is removed using just one line of code in the Form_Unload event: Form_frmDimmer.UnDim
The effect of altering the opacity can easily be tested by altering the combo value on the start form. For example, set to 40%:
If the value is set to 100%, the background is completely blacked out
All the code needed to achieve this is contained in form frmDimmer. The code isn't mine, but unfortunately I don't know the author's name.
The code is fairly complex and uses several APIs to achieve this effect. However, you do not need to understand the code in order to use it.
Just import the form frmDimmer into your own application and add the two code lines listed above to the popup form load / unload events.
Choose the opacity value that works best for you. In this example app, this is set using the combo and stored in tblSettings.
The function GetOpacity in modFunctions retrieves the stored value
The following code is used in frmDimmer:
CODE:
'Form declarations section
Private TargetOpacity As Integer
Private Const StepSize = 3
'================================
Private Sub Form_Load()
' Fill screen
Me.Move 0, 0, modMetrics.AccessAppInsideSize.Width, modMetrics.AccessAppInsideSize.Height
' Opacity can't be set until Visible=True
Me.Visible = True
SetOpacity Me, 0
DoCmd.Maximize
End Sub
'================================
Private Sub Form_Current()
Dim Opacity As Integer
For Opacity = 0 To TargetOpacity Step StepSize
SetOpacity Me, (Opacity)
DoEvents
Next Opacity
End Sub
'================================
Public Sub SetOpacity(frm As Access.Form, AlphaPercent As Byte)
If frm.PopUp Then
'set opacity value from tblSettings
'disable if using the constant value
TargetOpacity = GetOpacity 'function in modFunctions
'more code here to set form alpha value and extended attributes. . .
End If
End Sub
If preferred, you can instead set the opacity as a constant in the declarations section of frmDimmer:
Private Const TargetOpacity = 80 '50 etc
If you do this, remove the line Private TargetOpacity As Integer from the declarations section together with the line TargetOpacity = GetOpacity from the SetOpacity procedure.
NOTE:
It is VERY important that users do NOT open frmDimmer directly from the navigation pane as doing that would make the application unresponsive
Attempting to open the form directly, triggers this message:
This is done by using the following code in the Form_Open event:
Private Sub Form_Open(Cancel As Integer)
If Application.CurrentObjectName = Me.Name Then
FormattedMsgBox "This form is designed to be used in conjunction with other forms. " & vbCrLf & _
"@It cannot be opened directly from the navigation pane @", vbExclamation, "Action not allowed!"
Cancel = True
Exit Sub
End If
End Sub
NOTE:
The form frmDimmer is hidden in the example app. To import this form into your own apps, you will need to first make it visible.
Click Navigation Options then tick Show Hidden Objects. You can then import the form in the usual way.
Video
I have created a YouTube video (6:18) to accompany this article:
You can watch the Highlight Entire Form (Dim Background) video on my Isladogs YouTube channel or you can click below:
If you liked the video, please subscribe to my Isladogs on Access channel on YouTube. Thanks.
Feedback
Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.
Please also consider making a donation towards the costs of maintaining this website. Thank you
Colin Riddington Mendip Data Systems Last Updated 10 Oct 2024
Return to Example Databases Page
|
Return to Top
|