VB Migration Partner can be extended by means of extender DLLs, which can be written in any .NET language, including VB.NET or C#. This article shows how to write an extender that is capable to change the design-time value of controls’ properties by applying transformations that can’t be obtained by any pragma (including the ChangeProperty pragma).
First, launch Visual Studio and create a new Class Library project in your favorite .NET language. In this example we will use VB.NET.
Next, switch the References tab page of the MyProject node and add a reference to the following two VB Migration Partner DLLs: CodeArchitects.VBMigrationEngine.dll and CodeArchitects.VBLibrary.dll.
In the General tab page of the MyProject node assign a name to your extender DLL. In this case we will use the name PropertyProcessorExtender.
Rename the Class1.vb file appropriately – for example, PropertyProcessor.vb – and replace its contents with the following code:
<VBMigrationExtender ("Property processor", _
"Change the design-time value of controls' properties", _
Public Class PropertyProcessor
Public Sub Connect(ByVal data As ExtenderData) Implements IVBMigrationExtender.Connect
Public Sub Notify(ByVal data As ExtenderData, ByVal info As OperationInfo) _
Select Case info.Operation
Private Sub AssignProperties(ByVal info As OperationInfo)
If Not info.ProjectItem.HasDesigner Then Exit Sub
For Each comp As VBComponent In info.ProjectItem.Component.Components
Dim type As String = comp.TypeName
If type = "VB.Label" OrElse type = "VB.CommandButton" OrElse _
type = "VB.OptionButton" OrElse type = "VB.CheckBox" Then
Dim caption As String = comp.GetPropertyValue("Caption", "")
If caption <> "" Then
If type = "VB.CommandButton" Then
Dim left As Single = comp.GetPropertyValue("Left", 0.0!)
Dim top As Single = comp.GetPropertyValue("Top", 0.0!)
Dim width As Single = comp.GetPropertyValue("Width", 1215.0!)
Dim height As Single = comp.GetPropertyValue("Height", 495.0!)
comp.SetProperty("Left", left - 15)
comp.SetProperty("Top", top - 15)
comp.SetProperty("Width", width + 300)
comp.SetProperty("Height", height + 300)
Notice that an extender DLL can contain one or more extender classes, each one devoted to a specific task. It is essential that the DLL contains only a single assembly-level VB6SupportLibrary attribute, as displayed in code above.
Individual extender classes can be enabled from the Extensions tab of the Tools-Options dialog box in VB Migration Partner. The first two arguments for the VBMigrationExtender attribute are the extender name and description and are displayed in the Extensions tab. If the third argument is true then you don’t have to manually enable this extender from inside the dialog.
You can now compile the DLL and deploy it in VB Migration Partner’s setup folder. Quit VB Migration Partner (if currently running) and launch it again. You can now migrate any VB6 project and see how controls are affected. You can also set breakpoints to debug your extender DLL, as you’d do with any .NET project.