VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[PRB] The ClientSize property of a form can return an incorrect value

If you modify a migrated .NET form without a control box (i.e. ControlBox=False) inside the Visual Studio designer, then at runtime the ClientSize property will return an incorrect value that differs from the value stored in the code-behind portion of the form. There are two ways to solve this anomaly.

First, you can force the correct form size in the Form_Load method:

    ' VB.NET
    Private Sub Form_Load() Handles MyBase.Load
           Me.ClientSize = New System.Drawing.Size(, )
    End Sub

    // C#
    private void Form_Load() 
    {
           this.ClientSize = new System.Drawing.Size(, );
    }

Second, you can override the OnResize method as follows:

    ' VB.NET
    Protected m_PreClientSize As Size

    Protected Overrides Sub OnResize(e As EventArgs)
           If (MyBase.BorderStyle = VBRUN.FormBorderStyleConstants.vbFixedDouble OrElse
           MyBase.BorderStyle = VBRUN.FormBorderStyleConstants.vbSizableToolWindow) 
           AndAlso MyBase.ControlBox = False AndAlso 
           (MyBase.Location.X <> 0 OrElse MyBase.Location.Y <> 0) Then
                   MyBase.ClientSize = m_PreClientSize
                   Exit Sub
           End If
           
           m_PreClientSize = MyBase.ClientSize
           MyBase.OnResize(e)
    End Sub

    // C#
    protected Size m_PreClientSize As Size

    Protected Overrides void OnResize(EventArgs e)
    {
           if ((base.BorderStyle == VBRUN.FormBorderStyleConstants.vbFixedDouble ||
           base.BorderStyle == VBRUN.FormBorderStyleConstants.vbSizableToolWindow)
           && base.ControlBox == false &&
           (base.Location.X != 0 || base.Location.Y != 0) 
           {
                  base.ClientSize = m_PreClientSize;
                  return;
            }

            m_PreClientSize = base.ClientSize;
            base.OnResize(e);
    }
Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers