I had the opportunity to play with the source code of a large accounting package written in VB 6 with good friend Andrew Parsons and we thought “what the heck wonder how hard it would be to upgrade to .NET”.  

 

We kicked off the Upgrade wizard and went to have a beer and before we finished the upgrade Wizard had coughed up it’s _UpgradeReport.htm …. And as you would expect there were LOTS of errors.  The cool thing was many of them were simple things like the clipboard object and dll declare statements (Andrew went through these like a hot knife through butter)  - unfortunately most of the weren’t easy and they all involved printing –either to a form or printer and I thought would post a primer for other people that may have run into this…

 

Starting with form and the line of code in VB that simply draws where ever you drag the mouse:

 

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Me.Line (X, Y)-Step(5, 5), &HFF00&, BF

End Sub

 

I opened the project in Visual Studio/VB.NET and received the following as output (and an error indicating it couldn’t be upgraded):

 

Private Sub Form1_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

            Dim Button As Short = eventArgs.Button \ &H100000

            Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000

            Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)

            Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)

            'UPGRADE_ISSUE: Form method Form1.Line was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'

            Me.Line (X, Y) - (5, 5), &HFF00, BF

End Sub

 

 

Since we have both played with GDI+ before we knew the last line needed to be changed from drawing a line from the form object to using a graphics object created from the form as seen in the code below:

 

Private Sub Form1_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

            Dim Button As Short = eventArgs.Button \ &H100000

            Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000

            Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)

            Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)

           Dim g As Graphics = Me.CreateGraphics

             g.DrawLine(Pens.Green, X, Y, X + 15, Y + 5)

End Sub

 

Unfortunately we could see the upgrade wizard has converted my x and x coordinates from Pixels to twips and the drawing doesn’t match the mouse location; fixing this simply involved removing this “help” the upgrade wizard had supplied:

 

      Private Sub Form1_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

        Dim X As Single = eventArgs.X

        Dim Y As Single = eventArgs.Y

        Dim g As Graphics = Me.CreateGraphics

        g.DrawLine(Pens.Green, X, Y, X + 15, Y + 5)

    End Sub

 

 

This didn’t solve most of our problems as they involved printing not to a form but rather the printer and I will post that code next month/year/decade’s post