Tech Articles


Using Visual .NET Components in PowerBuilder


Microsoft recently released the Interop Forms Toolkit 2.0 in order to allow "developers to incorporate VB.NET Forms and Controls into their VB6 applications" (www.microsoft.com/downloads/details.aspx? FamilyID=934de3c5-dc85-4065-9327-96801e57b81d&DisplayLang=en).

The interesting thing is that it operates by automatically generating a COM Callable Wrapper (CCW) for the VB.NET forms and controls. That means that the .NET visual user controls are not only available to VB6, but to any Win32 application that supports COM, including PowerBuilder.

To test it out, I wrote a simple gradient user object in VB.NET (see Listing 1) and deployed it as an interop user control. I then added it to a PowerBuilder 10.5 window as an ActiveX (see Figure 1).

Everything on the window, with the exception of the gradient control, is standard PowerBuilder stuff. After some simple calculations to determine the combined RGB value the user has selected through the sliders and display it, it is applied to the gradient control through the following (of_calcstart and of_calcend are the routines used to calculate the RGB values):

long ll_start, ll_end
ll_start = of_calcstart()
ll_end = of_calcend()

//This will actually cause two repaints, but I don't care
ole_1.object.StartColor = ll_start
ole_1.object.EndColor = ll_end

The reason there are two repaints is because I force a repaint of the control whenever either the start or end color for the gradient is changed. The repaint happens fast enough so the user doesn't notice there were two.

Note that this technique will work not only for controls that you create in VB.NET, but also for third-party controls that can be used in VB.NET. For example, Figure 2 shows Dundas Charts working within a PowerBuilder window after being exposed as an interop control. Similarily, Figure 3 shows Infragistics' WinChart control operating in a PowerBuilder window.

The Interop Toolkit also allows you to expose VB.NET Forms as ActiveX controls (and has since the original 1.0 version), but I can't see much use for that. The important change with the 2.0 version is support for deploying controls.

Note that if you reference a third-party control in your user control, you will need to provide your own methods that will in turn interact with the third-party control. Just because the third-party control is visually exposed through the control doesn't mean that its properties and methods have been exposed.

In an earlier PBDJ article on CCWs I mentioned how manifests can be used so that such controls can be deployed as side-by-side assemblies and invoked through registry-free COM. That simplifies deployment by not requiring changes to the registry or the GAC. One additional significant feature of the Interop Toolkit is that it automatically generates the manifest information you would need if you opted for that deployment method.

Finally, if you're a bit of a C# snob (as I am), you might be initially put off that Microsoft only released the toolkit with support for VB.NET. Fortunately, a couple of people decided to take matters in their own hands and made additional templates for the toolkit available on the CodeProject Website that make the functionality available in C# as well. In particular, Leon Langleyben made one available just after the release of the 1.0 version of the toolkit that implemented forms (https://www.codeproject.com/kb/vb-interop/vb6interoptoolkit2.aspx), and more recently James Ashley made one available for the 2.0 version of the toolkit and controls (https://www.codeproject.com/Articles/15690/VB-C-Interop-Form-Toolkit).

To be honest, this isn't an ideal solution. What it does allow you to do is take advantage of Visual .NET controls in PowerBuilder now, until such time as PowerBuilder 12 is available and directly supports them.

 

--This article was originally published on PBDJ.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

Icon Import PDF Database Object Export JSON Source Code Array Testing Database Connection Database Table DataWindow UI Modernization InfoMaker Design 32-bit CoderObject DLL C# Source Control PowerServer Web Script PowerBuilder Compiler Windows OS NativePDF Class PBVM Filter SQL REST Stored Procedure Debugging Oracle Import JSON UI Themes Branch & Merge Resize Interface SqlModelMapper Database Painter Window BLOB Database Table Data IDE OLE Menu .NET Std Framework OAuth Database Table Schema Text MessageBox OAuth 2.0 Configuration COM Graph Git Expression Database Profile HTTPClient Installation Migration Event Handler PowerScript (PS) Event UI CI/CD Model Service .NET DataStore .NET Assembly TortoiseGit ODBC ActiveX Performance DataType iOS Web Service Proxy Messagging Elevate Conference PBNI Visual Studio Debugger SQL Server Authorization File Azure Windows 10 Icons Export Excel Deployment JSON Outlook TFS JSONParser OrcaScript Data PowerBuilder Encryption Automated Testing API SOAP Trial Jenkins SnapObjects DataWindow JSON CrypterObject Event Handling Application TLS/SSL Charts Encoding JSONGenerator RichTextEdit Control Platform Repository RESTClient Web API WebBrowser Mobile Database RibbonBar Linux OS SDK Debug GhostScript Error Bug License Android SVN SnapDevelop Sort PDFlib TreeView XML PostgreSQL DragDrop PostgreSQL ODBC driver SqlExecutor Authentication Variable RibbonBar Builder Validation 64-bit PFC Syntax WinAPI PBDOM PowerServer Mobile Transaction PowerBuilder (Appeon) Open Source External Functions DevOps