Color scheme: Dark
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Match the colors of the database design

How to: Match the colors of the database design

Show the WKL controls of a database in the colors of its design (Access: Design › Themes), or always light or always dark, so that lists, buttons and headers look like the Access controls around them.

Requires WKL Forms Object Library 1.47 or later.

Solution overview

  • ColorScheme is a property of every WKL control and of the WklToast object, with four values of WklColorScheme: wcoAutomatic (default), wcoLight, wcoDark and wcoHighContrast.
  • Automatic follows, in this order: the high contrast mode of Windows, then the color set of the database design, then light. A database without a design of its own and an Excel or Word UserForm draw light. Office's own design setting (File › Account › Office Theme) and the app mode of Windows are not followed: a database looks the same on every PC.
  • Colors you set win. BackColor and ForeColor follow the scheme only while they keep their system defaults (window, window text, button face). A color chosen in the property sheet or by code stays in every scheme.
  • Readable in every scheme. Text keeps a contrast of at least 4.5:1 to its background, lines and symbols at least 3:1; colors of a design that miss this are moved towards the text color.
  • High contrast always wins. In the high contrast mode of Windows every control draws with the system colors of the user's contrast theme, whatever ColorScheme says.

Implementation

Choose a design for the database once: open any form in design view, Design › Themes, and pick one (for example Riviera). The WKL controls left at wcoAutomatic take its color set the next time their form opens; nothing else is needed. Riviera, the theme of the WKL products, comes with the release package (themes\riviera); its colors and the rules for the marks are in themes\riviera.md of the release package.

To set the scheme in the designer: property sheet, tab Other, row Custom [...], page Darstellung, card Farbschema (ColorScheme).

To set it by code, for example a dark list on a start page and the notes of the application always light:

Option Compare Database
Option Explicit
 
Private mToast As WklToast
 
Private Sub Form_Load()
    Me!lstKunden.Object.ColorScheme = wcoDark
    Me!barKopf.Object.ColorScheme = wcoDark
 
    Set mToast = New WklToast
    mToast.ColorScheme = wcoLight
End Sub
 
Private Sub cmdSpeichern_Click()
    mToast.Show "Gespeichert.", wtkSuccess
End Sub

A form whose controls should all follow one choice of the user (for example a setting “dark mode” in an options table) sets the property in a loop:

Public Sub SetSchemeOfForm(ByVal frm As Form, ByVal scheme As WklColorScheme)
    Dim ctl As Control
    For Each ctl In frm.Controls
        If ctl.ControlType = acCustomControl Then TrySetScheme ctl, scheme
    Next
End Sub
 
' WklBadge, WklValidator and ActiveX controls of other vendors have no ColorScheme (error 438).
Private Sub TrySetScheme(ByVal ctl As Control, ByVal scheme As WklColorScheme)
    On Error Resume Next
    ctl.Object.ColorScheme = scheme
End Sub

Remarks

  • WklBadge and WklValidator have no ColorScheme: they draw only the colors of their kinds (info, warning, error), which keep their own pale fill and dark text on any background.
  • The color set is read through the database when the control is first drawn, never while Access draws the form, and again when the form opens anew or Requery runs. A design changed while the form is open shows after the form is opened again.
  • ColorScheme is saved with the form. A form saved without a value uses wcoAutomatic. Most databases carry Access's default design Office (Access adds it with the first form): their WKL controls then take its color set - the selection in the Office accent color, slightly gray headers - and so match the Access forms beside them. Set wcoLight where a control should keep the plain light look whatever the design.
  • WklToast keeps the setting only as long as the object lives; wcoAutomatic reads the color set once for each Show.
en/wiki/msaccess/comctl/how-to/match-the-colours-of-the-database-design.txt · Last modified: by Wolfgang van der Stille