Consume .NET Events

You can use PowerScript to dynamically connect methods to .NET events.

You can connect single or multiple methods to a .NET event in PowerScript. The method could be a PowerBuilder global function, an instance function of a PowerBuilder object, or an instance or static function of a .NET object. You can also connect PowerBuilder events to .NET events in PowerScript.

You are not able to declare a variable or a parameter with a .NET event because a .NET event is not a type at all. You are also not able to declare a new .NET event in PowerBuilder code; you can only consume a .NET event defined in other .NET languages with the += operator in PowerBuilder.

The following examples demonstrate how to dynamically hook up to a .NET event in PowerScript.

'Clicked' is a .NET event defined in the third-party .NET control 'system.windows.controls.button'. Suppose 'OnClick1' is a PowerBuilder event that has exact same signature as the 'Clicked' .NET event of 'System.Windows.Controls.Button' control. With this enhancement, you can support the following use cases.

Define a PowerBuilder event 'OnClick1':
Event OnClick1(system.object sender, RouteEventArgs e)
Connect 'OnClick1' to the 'Clicked' .NET event of an instance of 'System.Windows.Controls.Button' control:
System.Windows.Controls.Button cb1
cb1 = create System.Windows.Controls.Button()
cb1.clicked += OnClick1
Connect a PowerBuilder event to a .NET event of the InnerControl of a PowerBuilder control:
System.Windows.Controls.Button b 
b = cb_1.InnerControl
b.Click += OnClick1