Class FormDesigner
Reads what a form module's designer declares: the form's class and designer properties, and its controls.
public static class FormDesigner
- Inheritance
-
FormDesigner
- Inherited Members
Remarks
A form module (.frm) opens on a VERSION 5.00 header line and a designer block:
Begin <class> <name> … End, before its code-behind. What the block holds depends on the
designer that wrote it:
- A VBA UserForm (
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} UserForm1) holds the form's own properties only. Its controls are in the designer data Microsoft Forms persisted, which the VBE exports to the companion.frxfile at theOleObjectBlobproperty's offset: a 24-byte blob header, whose bytes 4 to 7 are the length of what follows it, then a compound file ([MS-CFB]) holding the form's storage ([MS-OFORMS] 2.1.2). The blob header is not documented; its layout is what the VBE writes. - A Visual Basic 6.0 form (
Begin VB.Form Form1) holds its controls too, as nestedBegin…Endblocks, each with its properties;BeginProperty…EndPropertyblocks group a property's own properties (aFont). Its.frxfile holds binary property values (pictures, lists), which a property cites as"Form1.frx":0000. The controls' declarations do not need it; the library that hosts the form reads it with the designer block's text (DesignerText).
The reader takes the companion file's content from its caller, which owns the file system: CompanionOf(string?) says which file and where.
Fields
MSFormsClassId
The class identifier of the Microsoft Forms 2.0 designer, which names a VBA UserForm's designer block.
public static readonly Guid MSFormsClassId
Field Value
MSFormsLibrary
The name of the Microsoft Forms type library, which qualifies the classes of a UserForm and of its controls (MSForms.TextBox).
public const string MSFormsLibrary = "MSForms"
Field Value
Methods
CompanionOf(string?)
Where the designer data of the form module source is, or null when the module is not a
form module or keeps no designer data in a companion file.
public static FormDesignerReference? CompanionOf(string? source)
Parameters
sourcestringThe form module's source.
Returns
Remarks
A VBA UserForm's is at its OleObjectBlob property's offset. A Visual Basic 6.0 form's is the whole file that the first
property citing one names, in the form's block or in any of its controls', grouped properties included
(Picture = "Form1.frx":0000), at offset 0.
Exceptions
- FormDesignerFormatException
The designer block is not terminated.
Read(string?, ReadOnlyMemory<byte>)
What the form module source declares, or null when it is not a form module (it has no
designer block).
public static FormDescriptor? Read(string? source, ReadOnlyMemory<byte> companion = default)
Parameters
sourcestringThe form module's source.
companionReadOnlyMemory<byte>The content of the module's companion file (CompanionOf(string?)), when the module keeps designer data there; ignored when it does not.
Returns
Remarks
A VBA UserForm's controls are read from its designer data, which is the descriptor's State. A Visual Basic 6.0 form's are
read from its text; its DesignerText is that text, and its State the whole companion file,
or empty when companion is.
Exceptions
- FormDesignerFormatException
The designer block is not terminated, a VBA UserForm keeps designer data in a companion file and
companionis empty, or that designer data cannot be read.
Read(string?, ReadOnlyMemory<byte>, out FormDesignerFormatException?)
What the form module source declares, as Read(string?, ReadOnlyMemory<byte>) reads it, or null when it is not a
form module or its designer data cannot be read, which problem then says.
public static FormDescriptor? Read(string? source, ReadOnlyMemory<byte> companion, out FormDesignerFormatException? problem)
Parameters
sourcestringThe form module's source.
companionReadOnlyMemory<byte>The content of the module's companion file (ReadCompanion(IFileSystem, string, string?, out Exception?)).
problemFormDesignerFormatExceptionWhy the designer data cannot be read (Problem);
nullwhen it was read, and for a module that is not a form module.
Returns
Remarks
A form whose designer data cannot be read declares nothing, so its module is loaded as one whose form has no controls.
ReadCompanion(IFileSystem, string, string?, out Exception?)
Reads the companion file of the form module at modulePath: the file its source names (CompanionOf(string?)), which is
beside the module's own file.
public static ReadOnlyMemory<byte> ReadCompanion(IFileSystem fileSystem, string modulePath, string? source, out Exception? problem)
Parameters
fileSystemIFileSystemThe file system the module is on.
modulePathstringThe path of the form module's file.
sourcestringThe form module's source.
problemExceptionWhy the companion file was not read: a FormDesignerFormatException when the designer block is not terminated, an IOException when the file cannot be read.
nullwhen it was read, and when there is none to read.
Returns
- ReadOnlyMemory<byte>
The content of the companion file. Empty, with no problem, when the module names no companion file or the file is not there; empty, with the problem, when the designer block or the file cannot be read.
Remarks
A program that loads a workspace's form modules reads each one's companion with its text, then gives both to Read(string?, ReadOnlyMemory<byte>, out FormDesignerFormatException?). A module whose companion is not read is still loaded. A VBA UserForm's controls are in its companion, so without it the read gives the problem and the form declares no controls. A Visual Basic 6.0 form's controls are in its text, so it declares them, with an empty State.
StateOf(string?, ReadOnlyMemory<byte>)
The designer's state of the form module source: for a VBA UserForm, the compound file its companion file keeps at the offset its
OleObjectBlob says, which is what Microsoft Forms loads a form from (IPersistStorage); for a Visual Basic 6.0 form, the whole companion
file. Empty when the module keeps no designer data in a companion file.
public static ReadOnlyMemory<byte> StateOf(string? source, ReadOnlyMemory<byte> companion)
Parameters
sourcestringThe form module's source.
companionReadOnlyMemory<byte>The content of the module's companion file (CompanionOf(string?)).
Returns
Remarks
The state is opaque here: Read(string?, ReadOnlyMemory<byte>, out FormDesignerFormatException?) reads what a UserForm declares from it, and the form host hands it, as it is, to the library that hosts the form.
Exceptions
- FormDesignerFormatException
The designer block is not terminated, a VBA UserForm keeps designer data in a companion file and
companionis empty, or the designer data is not where it says.