WARNING #2065

    <form1> event <form1>.<event1> has a new behavior.

    Description

    During the upgrade process, some events can be mapped to .NET with minor behavior differences. If this EWI is displayed in a given project, the selected target event will not threaten the functional equivalence of the resulting code but can create small differences that may require some manual fine tuning.

    Recommendations

    Each case will have to be evaluated individually, as the behavior differences may not be significant for every project. Some common properties with new behaviors include the following:

    • System.Windows.Forms.Control.Controls collection, which is a hierarchical list of NamingContainers and is usually navigated recursively. It's important to remember that Child controls will not be in the parent's Controls collection.
    • Likewise, System.Windows.Forms.ControlCollection.Count does not represent the same number in .Net as in VB6, as only direct descendants of the current control will be counted. Any child controls will be part of their respective parent's ControlCollection.
    • In this example, Form.Picture generates the EWI because the Picture property is replaced by the BackgroundImage property. In .Net, if the image assigned to the BackgroundImage property is smaller than the form, it will be tiled by default. In VB6, it is simply displayed in the top left corner of the form.

    Sample VB6

    Public Sub ShowPicture(ByVal myForm As Form)
       MsgBox(myForm.Picture.Height)
    End Sub
    

    Target VB.NET

    Public Sub ShowPicture(ByRef myForm As Form1)
       'UPGRADE_WARNING: (2065) Form property myForm.Picture has a new behavior.
     MessageBox.Show(CStr(myForm.BackgroundImage.Height), Application.ProductName)
    End Sub
    

     

    In some cases the migrated Property or method will behave in a manner that is inconsistent with the desired functionality.

    In this case, the Picture property for example will behave different than .Net's BackgroundImage when the image assigned is smaller than the form. In Visual Basic 6 the image would be displayed in the top left corner, while in .Net it's tiled across the form.

    In this particular example we're merely accessing the Height property, so we might be tempted to strip out the EWI comment and leave it at that. However, the Height property in Visual Basic 6 returns a value in HiMetric units, where as in .Net it's in pixels! So we can't leave the code as is and maintain functional equivalence.Assuming, the application still requires HiMetric units be returned, we'll need to convert the value to HiMetric units.

    For the sake of brevity we'll just assume that a PixelsToHiMetric method has already been coded for just this purpose.

    Public Sub ShowPicture(ByRef myForm As Form1)
       'Convert Pixels to HiMetric
    MessageBox.Show(CStr(PixelsToHiMetric(myForm.BackgroundImage.Height)), Application.ProductName)
    End Sub
    

    Target C#

    static public void ShowPicture(Form1 myForm)
    {
         //UPGRADE_WARNING: (2065) Form property myForm.Picture has a new behavior.
         MessageBox.Show(myForm.BackgroundImage.Height.ToString(), Application.ProductName);
    }
    

     

    In some cases the migrated Property or method will behave in a manner that is inconsistent with the desired functionality.

    In this case, the Picture property for example will behave different than .Net's BackgroundImage when the image assigned is smaller than the form. In Visual Basic 6 the image would be displayed in the top left corner, while in .Net it's tiled across the form.

    In this particular example we're merely accessing the Height property, so we might be tempted to strip out the EWI comment and leave it at that. However, the Height property in Visual Basic 6 returns a value in HiMetric units, while the property in .Net returns it in pixels. So we can't leave the code as is and maintain functional equivalence. Assuming, the application still requires HiMetric units be returned, we'll need to convert the value to HiMetric units.

    For the sake of brevity we'll just assume that a PixelsToHiMetric method has already been coded for just this purpose.

    static public void ShowPicture(Form1 myForm)
    {
         //UPGRADE_WARNING: (2065) Form property myForm.Picture has a new behavior.
         MessageBox.Show(PixelsToHiMetric(myForm.BackgroundImage.Height).ToString(), Application.ProductName);
    }
    

    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration