Workspace: IWorkspace;
The Workspace property determines a workspace.
Executing the example requires that the repository contains a form and a workspace with WORKSPACE identifier. Place the following components on the form: Button, WorkspaceBox, UiWorkspaceObject named Button1, WorkspaceBox1, and UiWorkspaceObject1.
Add links to the Andy, Drawing, Fore, ExtCtrls, Forms, MathFin, Metabase, and Workspace system assemblies.
Class TESTForm: Form
Button1: Button;
UiWorkspaceObject1: UiWorkspaceObject;
WorkspaceBox1: WorkspaceBox;
Sub IUIWORKSPACEEVENTARGS_WORKSPACEFormOnCreate(Sender: Object; Args: IEventArgs);
Var
Mb: IMetabase;
Workspace: IMetabaseObjectDescriptor;
Begin
// Get workspace
Mb := MetabaseClass.Active;
Workspace := Mb.ItemById("WORKSPACE").Edit;
// Set object opening parameters on form
UiWorkspaceObject1.Active := True;
UiWorkspaceObject1.Object := Workspace;
UiWorkspaceObject1.OperationMode := UiMetabaseObjectOperationMode.Edit;
WorkspaceBox1.Source := UiWorkspaceObject1 As IWorkspaceSource;
End Sub IUIWORKSPACEEVENTARGS_WORKSPACEFormOnCreate;
// Print workspace on button click
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Printer: IGxDocumentPrinter;
w: IGxDocument;
Begin
// Get printer for printing
Printer := GxPrinters.DefaultPrinter As IGxDocumentPrinter;
w := (UiWorkspaceObject1 As IDocumentSource).GetDocument;
// Print workspace
w.Print(Printer, -1, -1, "");
End Sub Button1OnClick;
// Set up the event that will occur after workspace print
Sub UiWorkspaceObject1OnAfterPrintWorkspace(Sender: Object; Args: IUiWorkspaceEventArgs);
Var
ui: IWxWorkspace;
shapesCount, i: Integer;
shape: IWxShape;
Begin
// Enter name of workspace for print
Debug.WriteLine("OnAfterPrintWorkspace - Form");
// Get workspace
ui := Args.Workspace As IWxWorkspace;
// Get collection of shapes and their number
With shapes: ui.Shapes Do
shapesCount := shapes.Count;
For i := 0 To shapesCount - 1 Do
// Get the current shape
shape := shapes.Item(i);
shape.Style.BeginUpdate;
// Generate random color and apply it to the shape
With r: Math.RandBetween(0, 255) As Integer, g: Math.RandBetween(0, 255) As Integer, b: Math.RandBetween(0, 255) As Integer Do
shape.Style.BackgroundBrushBackColor := New GxColor.CreateRGB(r, g, b);
End With;
shape.Style.EndUpdate;
End For;
End With;
End Sub UiWorkspaceObject1OnAfterPrintWorkspace;
End Class TESTForm;
After executing the example, the workspace with the WORKSPACE identifier is printed on button click. After the workspace is printed, shape color is changed for a random one.
See also: