Version 1.2 Approx 0.6 MB (zipped) First Published 2 Apr 2024
This is a feature that I previously included in several other example databases including: Control the Application Interface and the Attention Seeking Database
In this article, I am going to explain in more detail how you can add rounded corners to forms in any version of Access.
Rounded form corners seem to go 'in and out of fashion' in different versions of Windows and Access.
For example, in Access 2000/2003/2007/2010 the top corners are always rounded whether its the title bar or a borderless form
However in Windows 10 with recent version of Access from A2013 onwards, all corners have been 'square' in keeping with a supposedly more 'modern' look.
This was reversed with the release of Windows 11 where corners again became rounded!
However, it is easy to create rounded corners in e.g. Windows 10 and Access 365 using simple API calls.
You can choose to only round the top corners . . .
. . . or you can round all 4 corners . . .
In each case, the amount of rounding can be changed from the 10 (twips) used in the previous two screenshots.
In the next top rounding example, the value has been increased to 100 (twips).
Here all 4 corners are rounded with a value of 100
In each case, take care not to increase the value too far as you may lose information from the corners of the form
The effect works best with a borderless form. For other border types, the result will look slightly odd.
For an extreme version of this effect, you can even have a circular form. However, layout may be a bit tricky to manage
For consistency, I have also added a circular Close button using standard button control formatting.
Download
Click to download:
Rounded Corners v1.2 ACCDB file Approx 0.6 MB (zipped)
How the Example App works
The main code is in the module modCreateRoundCorners:
CODE:
Option Compare Database
Option Explicit
'https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createroundrectrgn
'The CreateRoundRectRgn function creates a rectangular region with rounded corners.
Private Declare PtrSafe Function CreateRoundRectRgn Lib "gdi32" ( _
ByVal nLeftRect As Long, ByVal nTopRect As Long, ByVal nRightRect As Long, _
ByVal nBottomRect As Long, ByVal nWidthEllipse As Long, ByVal nHeightEllipse As Long) As LongPtr
'https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowrgn
'The SetWindowRgn function sets the window region of a window.
'The window region determines the area within the window where the system permits drawing.
Private Declare PtrSafe Function SetWindowRgn Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal hRgn As LongPtr, ByVal bRedraw As Boolean) As Long
Dim hRgn As LongPtr
'===============================================
Public Function UISetRoundRect( ByVal UIForm As Form, ByVal CornersInPixels As Integer, _
Optional ByVal TopCornersOnly As Boolean = True) As Boolean
'CR - changed CornersInPoxels from Byte to Integer to fix overflow error
Dim intRight As Integer
Dim intHeight As Integer
With UIForm
intRight = PixelsPerTwipsX(.WindowWidth)
intHeight = PixelsPerTwipsY(.WindowHeight)
If TopCornersOnly Then
intHeight = intHeight + CornersInPixels
Else
intHeight = intHeight + 1
End If
hRgn = CreateRoundRectRgn(0, 0, intRight, intHeight, CornersInPixels, CornersInPixels)
SetWindowRgn .hWnd, hRgn, True
End With
End Function
The PixelsPerTwipsX and PixelsPerTwipsY functions are standard conversion functions in module modTwipsPerPixels
To implement the rounded corners effect requires one line of code in the Form_Load event. For example:
UISetRoundRect Me, 25, True (top corners only / 25 twips)
UISetRoundRect Me, 50, False (all corners / 50 twips)
The circular form has the code: UISetRoundRect Me, 500, False in its Form_Load event
For the purpose of this example app, I needed to be able to adjust the rounding effect so I added two functions as arguments in the UISetRoundRect function:
UISetRoundRect Me, GetRoundingValue, CheckTopRounding
The function arguments are:
a) Me - applies to the current form
b) GetRoundingValue - determines the amount of rounding in twips set using the combobox and stored in tblSettings
c) CheckTopRounding - True if just top corners are to be rounded, otherwise False for all corners
The code for these two functions is in modFunctions:
Function CheckTopRounding() As Boolean
CheckTopRounding = False
If Nz(DLookup("ItemValue", "tblSettings", "ItemName='TopRoundingOnly'"), "No") = "Yes" Then CheckTopRounding = True
End Function
'===============================================
Function GetRoundingValue()
GetRoundingValue = Nz(DLookup("ItemValue", "tblSettings", "ItemName='RoundingValue'"), "10")
End Function
These values are then updated using the checkboxes and combobox on the main form with the latest values stored in table tblSettings
Video
A video explaining the features and code used in this app is now available on YouTube.
You can watch the Rounded Corners in Forms 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 2 Apr 2024
Return to Example Databases Page
|
Return to Top
|