Screen Script Structure
Screen Script Structure
- The generated screen script follows a standard C# class structure. (You can also design it as a VB script, but the examples here are in C#).
- All code is contained within a class named MainClass.
- This structure consolidates both SCADA tag access and screen events in a single central location.
Object Types and Casting
When accessing an object within the screen script, casting it to the correct C# type is crucial. All objects are fundamentally derived from the System.Windows.Forms.Control class.
- Defining as “Control”
This is a safe and generic definition method for all objects. In this case, you can only access common properties such as Location, Size, and Visibility.
- Defining as a “Specific Type”
For standard Windows objects (e.g., Button, TextBox), you should use their specific type. This allows you to access all properties and methods unique to that object (e.g., .Text, .Click).
| Rule | Scenario | Definition Method | Example Access |
| Control | Accessing special SCADA objects like Visualization/Alarm Components or accessing only basic properties (Position, Size) of an object. | Control AlarmView_1; | AlarmView_1.Width = 123; |
| Specific Type | Accessing all properties of standard Windows Form objects like Buttons, Text Boxes. | Button Button_0; | Button_0.Text = “New Text”; |
// Import required .NET namespaces.
// These libraries provide access to Windows Forms components and basic system functions.
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.CSharp;
// Main class of the screen script.
// Each screen in Wise SCADA uses its own MainClass to handle logic and events.
public class MainClass
{
// =========================
// GLOBAL FIELD DECLARATIONS
// =========================
public BOOL Beep; // A SCADA-specific Boolean variable (linked to a SCADA tag or used internally)
Form ScreenForm; // Represents the current screen (Form)
Button Button_0; // Represents a button object on the screen
Control AlarmView_1; // Represents a SCADA alarm view control (generic Control type)
// =========================
// MAIN ENTRY METHOD
// =========================
public void Main()
{
// This method runs automatically when the script is initialized.
// It can be used to set default values or perform one-time setup actions.
Beep = true; // Example: activate a beep or set an initial condition
}
// =========================
// SCREEN LOAD EVENT
// =========================
public void Screen_Load(Object sender, EventArgs e)
{
// The sender parameter represents the screen object (Form) that triggered the event.
ScreenForm = sender as Form;
// Find and link controls from the screen by their names.
Button_0 = ScreenForm.Controls["Button_0"] as Button;
AlarmView_1 = ScreenForm.Controls["AlarmView_1"] as Control;
// Modify a general property of the alarm view (width).
AlarmView_1.Width = 123;
// Alternative approach (commented out):
// If the control is not directly on the form (e.g., inside a Panel),
// use the Find() method to search within nested controls.
// Button_0 = ScreenForm.Controls.Find("Button_0", true).FirstOrDefault() as Button;
}
// =========================
// SCREEN CLICK EVENT (WHEN CLICKING EMPTY AREA)
// =========================
public void Screen_FormClicked(Object sender, EventArgs e)
{
// Triggered when the user clicks anywhere on the screen background. Example: change the text of a button dynamically.
Button_0.Text = "Clicked!";
}
// =========================
// BUTTON DOUBLE-CLICK EVENT
// =========================
public void Button_0_DoubleClick(Object sender, EventArgs e)
{
// sender represents the object that raised this event.
// (The line below is optional; the button is already initialized in Screen_Load.)
// Button_0 = sender as Button;
// Closes the current screen.
ScreenForm.Close();
// Writes a value to a SCADA tag dynamically.
// Example: set the tag "Tag_0" to the value 123.
TagSet("Tag_0", 123);
}
}
Best Practices and Rules
| Topic | Description / Warning | Recommended Practice |
| Event Structure | Every event method (Screen_Load, etc.) is automatically generated by the system inside MainClass. | Do not manually delete or rename events. This will break the link with the SCADA system. |
| SCADA Tag Access | You can access and assign values to tags directly within the script. Incorrect names cause runtime errors. | Use operations like TagSet(“Tag_0”, 123); only when you are sure the tag name is correct. |
| Object Binding (Control Mapping) | Objects on the screen cannot be accessed directly by name. They must be linked via the form when the screen loads. | Define mapping for every object in Screen_Load like: ScreenForm.Controls[“Button_0”] as Button; |
| Field Definition | If a control variable is defined only inside a method, other event methods cannot access it. | Define objects at the top of the class (Global Field) so they are accessible everywhere (e.g., Button Button_0;). |
| Casting (Type Conversion) | Controls[“Name”] returns a generic Control. Its specific properties cannot be accessed without casting. | Cast to the appropriate type: Button_0 = ScreenForm.Controls[“Button_0”] as Button; |
| Control vs. Specific Type | Every object is derived from Control. If defined as Control, you only get generic properties. | If you need specific properties (e.g., Button.Text), define that object as its Specific Type. |
