WklImage
WklImage class
Signature
Dim myWklImage As WklImage Set myWklImage = Me!ControlName.Object
Summary
A picture from a file, a shared image of the database, SVG text or a data URI: SVG drawn with Direct2D, sharp at every size and in print; PNG, JPEG, BMP, GIF and ICO as well as EMF and WMF drawn with GDI+.
Parameters
None
Remarks
The source is read in this order: a text that starts with < is SVG; a text that starts with data: is a data URI (data:image/png;base64,… or URL-encoded SVG); a text with a path separator, a drive or a file extension is a file - a relative path is relative to the folder of the database (CurrentProject.Path); any other text is the name of a shared image of the database (Access's image gallery). Addresses on the network (http:, https:) are refused: the control does not load from the internet.
Bound - Control Source of the Access control set to a field - Access writes the field into Value on every record change: text is read as a source as above, bytes (a Long Binary field filled by code, for example from an ADODB.Stream) as a picture. A value other than Null takes the place of Source; Null shows Source again. A bound image never writes back.
The picture is loaded when it is first drawn after a change, not when the source is set. A source that cannot be shown - a missing file, a damaged picture, an SVG that is not XML - is no error for the form: the control shows the reason instead and ErrorText returns it.
SVG: currentColor takes the color SvgColor, so single-color icon sets follow the form's design. Direct2D draws the common SVG of icons and drawings (paths, basic shapes, gradients, transforms); text and filter effects of SVG are not drawn. Direct2D's SVG needs Windows 10 version 1703 or later.
The designer (row Custom [...] of the property sheet in design view, Opening the designer) sets the source - with a file dialog and a preview - the size mode and the colors.
An ActiveX control: inserted into a form in design view (Form Design › Controls › ActiveX Controls); reports are not supported. VBA reaches it through the Object property of the control, where ControlName is the name of the control on the form.
| Member | Kind | Summary |
|---|---|---|
| `Value` | Property | Gets or sets the bound value: a source text or the bytes of a picture. |
| `Source` | Property | Gets or sets where the picture comes from. |
| `SizeMode` | Property | Gets or sets how the picture fills the control. |
| `SvgColor` | Property | Gets or sets the color that replaces currentColor in an SVG picture. |
| `BackColor` | Property | Gets or sets the background color, visible where the picture is transparent or does not reach. |
| `ErrorText` | Property | Gets why the picture cannot be shown. |
| `PictureWidth` | Property | Gets the natural width of the picture. |
| `PictureHeight` | Property | Gets the natural height of the picture. |
| `Reload` | Method | Reads the file or the shared image again, for example after the file was replaced. |
| Event | Summary |
|---|---|
| `Click` | Occurs when the user clicks the picture in form view. |
Code example
' A single-color SVG symbol in the color of the form's title.
Private Sub Form_Load()
With Me!imgSymbol.Object
.Source = "symbole\lager.svg" ' relative to the folder of the database
.SizeMode = wimZoom
.SvgColor = Me!lblTitel.ForeColor
If Len(.ErrorText) > 0 Then Debug.Print .ErrorText
End With
End Sub
Inheritance
None
Value property
Signature
Property Get Value() As Variant Property Let Value(RHS As Variant)
Summary
Gets or sets the bound value: a source text or the bytes of a picture.
Parameters
None
Property value: Variant – A text read like Source, a byte array with a picture, or Null (default) to show Source.
Remarks
Access writes the value of the Control Source into it on every record change; code may set it too. The value is not stored with the form, and the control never reports it back to Access.
Read/write.
Code example
None
Inheritance
Declared by WklImage.
Source property
Signature
Property Get Source() As String Property Let Source(RHS As String)
Summary
Gets or sets where the picture comes from.
Parameters
None
Property value: String – A file (absolute, or relative to the folder of the database), the name of a shared image of the database, SVG text starting with <, or a data URI; empty (default) for no picture.
Remarks
A URL raises wkeInvalidValue at the assignment. Outside Access (UserForms) a relative path is relative to the current folder of the process, and shared images are not available. The source is stored with the form; for a large picture prefer a file or a shared image to SVG text.
Read/write.
Code example
None
Inheritance
Declared by WklImage.
SizeMode property
Signature
Property Get SizeMode() As WklImageSizeMode Property Let SizeMode(RHS As WklImageSizeMode)
Summary
Gets or sets how the picture fills the control.
Parameters
None
Property value: `WklImageSizeMode` – wimClip, wimStretch or wimZoom (default).
Remarks
Values outside the enumeration raise wkeInvalidValue.
Read/write.
Code example
None
Inheritance
Declared by WklImage.
SvgColor property
Signature
Property Get SvgColor() As OLE_COLOR Property Let SvgColor(RHS As OLE_COLOR)
Summary
Gets or sets the color that replaces currentColor in an SVG picture.
Parameters
None
Property value: OLE_COLOR – An OLE color, system colors included; default the window text color of Windows.
Remarks
Has no effect on bitmaps and on SVG pictures without currentColor.
Read/write.
Code example
None
Inheritance
Declared by WklImage.
BackColor property
Signature
Property Get BackColor() As OLE_COLOR Property Let BackColor(RHS As OLE_COLOR)
Summary
Gets or sets the background color, visible where the picture is transparent or does not reach.
Parameters
None
Property value: OLE_COLOR – An OLE color; default the window color of Windows.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklImage.
ErrorText property
Signature
Property Get ErrorText() As String
Summary
Gets why the picture cannot be shown.
Parameters
None
Property value: String – The reason, for example the path of a file that cannot be read; empty when the picture is shown or there is no source.
Remarks
Read-only.
Code example
None
Inheritance
Declared by WklImage.
PictureWidth property
Signature
Property Get PictureWidth() As Long
Summary
Gets the natural width of the picture.
Parameters
None
Property value: Long – Pixels (for SVG at 96 dpi, from width or the viewBox; 300 when the file gives neither); 0 without a picture.
Remarks
Read-only.
Code example
None
Inheritance
Declared by WklImage.
PictureHeight property
Signature
Property Get PictureHeight() As Long
Summary
Gets the natural height of the picture.
Parameters
None
Property value: Long – Pixels (for SVG at 96 dpi, from height or the viewBox; 150 when the file gives neither); 0 without a picture.
Remarks
Read-only.
Code example
None
Inheritance
Declared by WklImage.
Reload method
Signature
Sub Reload()
Summary
Reads the file or the shared image again, for example after the file was replaced.
Parameters
None
Remarks
None
Code example
None
Inheritance
Declared by WklImage.
Click event
Signature
Event Click()
Summary
Occurs when the user clicks the picture in form view.
Parameters
None
Remarks
In a form module: Private Sub <ControlName>_Click(...). Parameters passed by reference can be changed by the procedure.
Code example
None
Inheritance
Declared by WklImage.