Scripting in Canvas
Use scripting in your Canvas screens to customize the logic governing screen design and control object functionality. Canvas supports both C# and VB.NET programming languages. The choice is yours, but use a single programming language within each screen. The script will compile the same, and the controls will provide the same functionality, so use the language you prefer.
By default, the Canvas application uses the C# script language. If you prefer to use VB.NET, select that option in the Backstage view when opening a new screen. You can select your preferred default script language in the General Settings page, Application settings section.
Note: Many outside resources are available, online and otherwise, to learn more about scripting and using specific programming languages.
Enabling Script
By default, the Canvas script editor and script engine are disabled. To enable scripting for any screen (or object), perform one of the following. Once enabled, scripting support cannot be disabled.
- Select the Script view tab of the Screen pane. Click the link Enable scripting for this screen to switch to the Script view.
- In the Events pane, click the check box or event name for an event to switch to the Script view.
Note: Enabling script support for a screen increases the overhead associated with initializing and running that screen. If you can avoid enabling script it will allow the screen to load faster and use fewer resources while running.
Script View
The Screen pane contains three views, accessible with the tabs at the bottom of the pane: the Design view, the Script view and the Controls view. Work in the Script view to customize screens with script, validate script, and manage assembly references. The structure of the script view is color-coded to help you quickly identify read-only and writable portions.
- White background — Indicates writable portions of script, and also contains helpful usage comments
- Gray background — Indicates read-only portions of script, and contains the structure and global class indicators for placing and manipulating the objects on your screen. It is recommended that you do not edit these portions without a compelling reason to do so. If deemed necessary to make it editable, you can do so - but be aware that it cannot be undone. Knowing this, to remove the read-only protections, right-click the gray script area to access the context-menu options, and then click Make editable. It will remain editable from that point forward. See Script View Context Menu.
Note: Use Ctrl+T to toggle between Design view and Script view in the Screen pane. If scripting is not yet enabled, click Enable scripting for this screen to open the Script view.
Screen Load Time
When a screen is saved in Canvas, any script assemblies are compiled into a uniquely named .dll file (using a GUID assigned to the screen) and the assembly is added to the .can file, so the script does not have to be recompiled every time the screen is run. When a screen is loaded in Canvas preview or Canvas.View, the precompiled .dll is extracted to a temporary directory and the script assembly is loaded from disk. This results in faster load times by removing the need to recompile script. The screen property Unique name (UniqueName) exposes this name. See Load time.
Temporary Files and Folders
The Canvas applications use a set of GUID-based file and folder names when viewing Canvas screens to avoid resource contention between temporary files. The GUID (the screen's globally unique ID) corresponds to the Unique name (UniqueName) property value. This is used to represent the folder name created in the temporary working directory. This folder is used to store all assemblies related to the screen. The temporary assembly will always use a fixed GUID when it is extracted from a screen, but it will be given a new random GUID if it is ever recompiled.
Script Examples
Canvas screen examples are available in two locations:
- in the CANEXAMP folder in the APPS
- in the Clients\Canvas\Screens\Examples folder on the local file system
Be sure to browse through these files to familiarize yourself with how scripting is commonly added to object events.
