Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page has information about the CodeBehind tab.


On this page:

Table of Contents
maxLevel3



1. Overview

The CodeBehind tab serves as a platform for defining functions linked to a display, written in either standard VB.Net or CSharp for WPF Clients and JavaScript for Web Clients. CodeBehind functions operate when opening, closing, or while the display is open, based on your code configuration.

CodeBehind is an essential tool for controlling display behavior and interactivity in FactoryStudio. It enables you to script custom functionalities and responses to user inputs or system changes, increasing the flexibility and adaptability of your interface.

2. Understanding CodeBehind

You can switch between VB.Net and CSharp, and the system automatically converts existing code to the chosen language. For your own assembly references, use Run → Build → References.

Additional Insight: The ability to switch between VB.Net and CSharp is a powerful feature that allows developers to leverage the strengths of both languages. Remember to thoroughly test your code after switching languages, as subtle differences between the two can lead to unexpected behaviors.

3. Pre-defined Methods

CodeBehind offers the following pre-defined methods:

  • DisplayOpening(): Executed when a display is opening.
  • DisplayIsOpen(): Called in regular intervals while the display is open.
  • DisplayClosing(): Executed when a display is closing.
  • DialogOnOK(): Called when the OK button on a dialog display is pressed. Returning 1 allows the dialog to close. Returning 0 prevents the dialog from closing.

Additional Insight: The predefined methods provide a solid starting point for common display events. Leveraging these can save time and ensure consistent behavior across displays. For more complex applications, consider extending these methods or adding new ones to better fit your needs.

4. Custom .NET Variables and Methods

You have the option to add your own .NET variables and methods to this page.

Additional Insight: Custom variables and methods can significantly enhance your control over display behavior. They enable more complex and tailored functionality, so consider their use for more advanced or specific user interactions.

5. Code Execution Considerations

When the CodeBehind runs on the client side, the display locks while the code is running. For lengthy procedures, opt for Scripts (tasks and classes) to prevent displays from locking for too long.

Additional Insight: Code execution efficiency is crucial in HMI SCADA systems. Long running code can block the user interface, leading to poor user experience. Always strive to optimize your CodeBehind routines and consider offloading heavy processing tasks to the server or background processes.

6. Using CodeBehind in Different Display Types

CodeBehind can be used to define the mouse and input command handling methods to be executed on a specific display.

Additional Insight: Mouse and input command handling are key for interactive displays. Consider using this feature to customize your user's interaction with each display, such as providing contextual menus on right-click, or keyboard shortcuts for frequent actions.

7. CodeBehind for Dialog Displays

In Dialog displays, use the built-in DialogOnOK method, which is called when the built-in OK button on the dialog is pressed. If "True" is returned on that method, the dialog is closed; if "False" is returned, the dialog remains open. This method is commonly used to ensure data validation on the dialog and prompts the user to correct incorrect entries before closing the dialog.

Additional Insight: Dialog displays are a powerful tool for data input and user interaction. Leverage the DialogOnOK method to perform data validation and user guidance. Remember that a good user experience often involves providing clear feedback on required corrections.

8. CodeBehind for Standard Displays

The functionality of the CodeBehind is equally significant for standard displays. Code can be executed at various points during the display's lifecycle, enabling dynamic behavior and interaction.

Additional Insight: Remember that code execution can affect performance. In standard displays, consider the trade-offs between interactivity and performance. For complex or computationally heavy operations, it may be better to handle these server-side or in background tasks.

9. References and Language Selection

To reference your own assemblies, use Run → Build → References. Language selection allows you to choose between VB.Net and CSharp, with the system automatically converting the existing code to the chosen language.

Additional Insight: When referencing assemblies, ensure they are compatible with your selected language and that they are correctly versioned. When changing languages, always review the converted code for potential translation issues as some constructs in VB.Net might not have direct equivalents in CSharp, and vice versa.

10. Advanced Tips and Best Practices

As the client displays are designed to operate in distributed and web environments, it is advisable to avoid using functions that don't allow partial trust execution or refer to physical file paths.

Additional Insight: In distributed environments, keeping security in mind is crucial. Avoiding the use of functions that do not allow partial trust execution helps protect your application from potential security threats. Also, hard-coding physical file paths can lead to problems in distributed or web deployments due to variations in directory structures or access permissions.

Overall, effective use of the CodeBehind functionality in FactoryStudio or any HMI SCADA system can significantly enhance the flexibility, usability, and security of your applications. Understanding the available methods and best practices is key to leveraging its full potential.





Overview

The CodeBehind tab is used to define a set of functions connected to a display. You can write code in either standard VB.Net or CSharp. You can also switch between both. If you change your language selection, the system automatically converts existing code to the selected language.

If you need references to your own assemblies, use Run → Build → References.

CodeBehind functions can be executed when opening or closing, or while the display is open, depending on how you configure the code. You can use CodeBehind to define the mouse and input command handling methods to be executed on a specific display.

For Dialog displays, use the built-in DialogOnOK method, which is called when the built-in OK button on the dialog is pressed. If "True" is returned on that method, the dialog is closed; if "False" is returned, the dialog remains open. This method is commonly used to ensure data validation on the dialog and prompts the user to correct incorrect entries before closing the dialog.

The Code Behind of the Displays has the following pre-defined methods:

  • DisplayOpening()Executed when a display is opening.
  • DisplayIsOpen()Called in regular intervals while the display is open.
  • DisplayClosing()Executed when a display is closing.
  • DialogOnOK()Called when the OK button on a dialog display is pressed. Returning 1 allows the dialog to close. Returning 0 prevents the dialog from closing.

You can add your own .NET variables and methods to this page. 

Info

Since the client displays are designed to run on distributed environments as well as web environments, we recommend to avoid using functions that do not allow partial trust execution or that refer to physical file paths.


Info

Once the CodeBehind runs on the client side, the display will be locked when the code is running. To avoid locked displays for too long, choose Scripts (tasks and classes) if the code has too many procedures.



In this section...

Page Tree
root@parent
spacesV10