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

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