Add logic to displays with CodeBehind.
How-to Guides → Pillars → Operator → Displays → CodeBehind | How-To Guide | Reference
Displays CodeBehind (Reference) provides server-side scripting capabilities for displays, with pre-defined event methods and custom functions in VB.NET, C#, or JavaScript (HTML5-only displays).
CodeBehind enables:
Access via Displays → Draw → CodeBehind tab.
Every display includes these event handlers:
Method | Triggered When | Purpose |
---|---|---|
DisplayOpening() | Display starts opening | Initialize variables, setup |
DisplayIsOpen() | While display remains open | Continuous updates, monitoring |
DisplayClosing() | Display starts closing | Cleanup, save state |
DialogOnOK() | OK button pressed (dialogs only) | Validate input, return 1 to close, 0 to prevent |
csharp
public void DisplayOpening()
{
// Initialize display
}
public void DisplayIsOpen()
{
// Called continuously while open
// Use sparingly for performance
}
public void DisplayClosing()
{
// Cleanup before close
}
public int DialogOnOK()
{
// Dialogs only - validate and return
if (ValidateInput())
return 1; // Allow close
else
return 0; // Prevent close
}
Local variables exclusive to the display instance:
csharp
// Set property value
SetCustomPropertyValue("PropertyName", value);
// Get property value
var value = GetCustomPropertyValue("PropertyName");
// Get all as string
string allProps = GetCustomPropertiesAsString();
// Clear all properties
ClearCustomProperties();
See → Custom Properties for detailed documentation.
csharp
public async void DisplayOpening()
{
await Task.Run(() => LongRunningOperation());
}
Special object available in CodeBehind:
csharp
// Access current display properties
this.CurrentDisplay.Width
this.CurrentDisplay.Height
this.CurrentDisplay.Name
// Get display framework element
this.CurrentDisplay.GetThis()
Multiple methods available:
Method | Auto-Updates on Rename | Usage |
---|---|---|
@Display.PageName.Open() | Yes | Preferred for pages |
@Display.PageName.NewPopup() | Yes | Create popup instance |
@Client.OpenDisplay("PageName") | No | String-based navigation |
@Client.NewPopup("PageName") | No | String-based popup |
csharp
public void DisplayIsOpen()
{
this.CurrentDisplay.GetThis().PreviewMouseWheel += PreviewMouseWheelChanged;
}
private void PreviewMouseWheelChanged(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
if (e.Delta > 0)
@Display.MainPage.ZoomLevel += 0.1;
else if (e.Delta < 0)
@Display.MainPage.ZoomLevel -= 0.1;
}
csharp
// Track popup instances
private List<object> openPopups = new List<object>();
public void OpenNewPopup(string data)
{
var popup = @Display.DetailPopup.NewPopup();
popup.SetCustomPropertyValue("Data", data);
openPopups.Add(popup);
}
public void CloseAllPopups()
{
foreach(var popup in openPopups)
{
popup.Close();
}
openPopups.Clear();
}
See → Multiple Popups for advanced scenarios.
See → Code Editor for complete feature documentation.
For using custom DLLs and assemblies:
See → Scripts References for configuration.
csharp
private bool initialized = false;
public void DisplayIsOpen()
{
if (!initialized)
{
InitializeDisplay();
initialized = true;
}
}
csharp
private DateTime lastUpdate = DateTime.MinValue;
public void DisplayIsOpen()
{
if (DateTime.Now - lastUpdate > TimeSpan.FromSeconds(1))
{
UpdateDisplay();
lastUpdate = DateTime.Now;
}
}
Display Freezing:
Methods Not Firing:
Variable Scope Issues: