How to: Show SVG symbols in the color of the form
Show a single-color symbol from an SVG icon set on a form, sharp at every size and in the color of the form's text, and change it for each record.
Requires WKL Forms Object Library 1.52 or later.
Solution overview
- A
WklImagecontrol draws the SVG file through Direct2D;SizeMode = wimZoomkeeps its aspect ratio. - Icon sets draw with
currentColor;SvgColorsets that color to the form's color. - When the control is bound to a field that holds the file name, the symbol follows the current record.
Implementation
Keep the symbols in a symbols folder next to the database, insert a WKL Image control named
imgSymbol, and set its Control Source to a Symbol field that holds the file name
(symbols\warehouse.svg):
Private Sub Form_Load()
With Me!imgSymbol.Object
.SizeMode = wimZoom
.SvgColor = Me!lblTitle.ForeColor ' the color of the form's title
.Source = "symbols\empty.svg" ' shown when the field is Null
End With
End Sub
Private Sub Form_Current()
If Len(Me!imgSymbol.Object.ErrorText) > 0 Then Debug.Print Me!imgSymbol.Object.ErrorText
End Sub
Remarks
- Relative paths start at the database folder (
CurrentProject.Path), so the symbols folder can move along with the database. - An SVG with its own colors ignores
SvgColor; onlycurrentColoris replaced. - Direct2D doesn't draw SVG text or filter effects; convert text to paths in your drawing program.
- A missing file shows its path in the control and in
ErrorText; the form keeps running.
Related topics
en/wiki/msaccess/comctl/how-to/show-svg-symbols-in-the-colour-of-the-form.txt · Last modified: by Wolfgang van der Stille