TODO #2018

    Remove the next line of code to stop form from automatically showing.

    Description

    VBUC converts MDI forms to regular .NET forms, but also applies specific conversion rules in order to emulate exactly the same behavior as in VB6. If that behavior is no longer wanted, then just remove the tagged comment and the line of code that calls the Show method of the form.

    Recommendations

    The MDI form in the VB6 project had its AutoShowChildren property set to True; to simulate the VB6 behavior, VBUC needs to automatically Show the form whenever it is loaded. If you do not want this behavior then delete the following lines of code:
    //UPGRADE_TODO: (2018) Remove the next line of code to stop form from automatically showing.
    this.Show();

    Sample VB6

    Private Sub MDIForm_Load()
    Form1Child.Show
    End Sub

    Target VB.NET

    PublicSubNew()

     

    MyBase.New()

     

    'This call is required by the Windows Form Designer.

     

    InitializeComponent()

    'This form is an MDI child.

     

    'This code simulates the VB6

     

    ' functionality of automatically

     

    ' loading and showing an MDI

     

    ' child's parent.

     

    Me.MdiParent = Project1.MDIForm1

     

    Project1.MDIForm1.Show()

    'The MDI form in the VB6 project had its

     

    'AutoShowChildren property set to True

     

    'To simulate the VB6 behavior, we need to

     

    'automatically Show the form whenever it

     

    'is loaded. If you do not want this behavior

     

    'then delete the following line of code

     

    'UPGRADE_TODO: (2018) Remove the next line of code to stop form from automatically showing.

     

    Me.Show()

     

    EndSub

    Expected VB.NET

    PublicSubNew()

     

    MyBase.New()

     

    'This call is required by the Windows Form Designer.

     

    InitializeComponent()

    'This form is an MDI child.

     

    'This code simulates the VB6

     

    ' functionality of automatically

     

    ' loading and showing an MDI

     

    ' child's parent.

     

    Me.MdiParent = Project1.MDIForm1

     

    Project1.MDIForm1.Show()

    'The MDI form in the VB6 project had its

     

    'AutoShowChildren property set to True

     

    'To simulate the VB6 behavior, we need to

     

    'automatically Show the form whenever it

     

    'is loaded. If you do not want this behavior

     

    'then delete the following line of code

     

    'UPGRADE_TODO: (2018) Remove the next line of code to stop form from automatically showing.

     

    Me.Show()

     

    EndSub

    Target C#

    public Form1Child():base(){

     

    if (m_vb6FormDefInstance == null)

     

    {

    if (m_InitializingDefInstance)

     

    {

    m_vb6FormDefInstance = this;

     

    } else

     

    {

    try

     

    {

    //For the start-up form, the first instance created is the default instance.

     

    if (System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType == this.GetType())

     

    {

    m_vb6FormDefInstance = this;

     

    }

    }

    catch

     

    {

    }

    }

    }

    //This call is required by the Windows Form Designer.

     

    InitializeComponent();

    //This form is an MDI child.

     

    //This code simulates the VB6

     

    // functionality of automatically

     

    // loading and showing an MDI

     

    // child's parent.

     

    this.MdiParent = Project1.MDIForm1.DefInstance;

     

    Project1.MDIForm1.DefInstance.Show();

     

    //The MDI form in the VB6 project had its

     

    //AutoShowChildren property set to True

     

    //To simulate the VB6 behavior, we need to

     

    //automatically Show the form whenever it

     

    //is loaded. If you do not want this behavior

     

    //then delete the following line of code

     

    //UPGRADE_TODO: (2018) Remove the next line of code to stop form from automatically showing.

     

    this.Show();

     

    }

    Expected C#

    public Form1Child():base(){

     

    if (m_vb6FormDefInstance == null)

     

    {

    if (m_InitializingDefInstance)

     

    {

    m_vb6FormDefInstance = this;

     

    } else

     

    {

    try

     

    {

    //For the start-up form, the first instance created is the default instance.

     

    if (System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType == this.GetType())

     

    {

    m_vb6FormDefInstance = this;

     

    }

    }

    catch

     

    {

    }

    }

    }

    //This call is required by the Windows Form Designer.

     

    InitializeComponent();

    //This form is an MDI child.

     

    //This code simulates the VB6

     

    // functionality of automatically

     

    // loading and showing an MDI

     

    // child's parent.

     

    this.MdiParent = Project1.MDIForm1.DefInstance;

     

    Project1.MDIForm1.DefInstance.Show();

     

    //The MDI form in the VB6 project had its

     

    //AutoShowChildren property set to True

     

    //To simulate the VB6 behavior, we need to

     

    //automatically Show the form whenever it

     

    //is loaded. If you do not want this behavior

     

    //then delete the following line of code

     

    //UPGRADE_TODO: (2018) Remove the next line of code to stop form from automatically showing.

     

    this.Show();

     

    }


    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