Previous | Index | Next 

[PRB] Assignments to VB6 Form’s Left and Top properties are ignored

Under VB6, if you assign the Left or Top property of a form before displaying the form, such assignments overrides the StartUpPosition property if this property is set to 3-Windows Default. However, if the property is set to 1-CenterOwner or 2-CenterScreen, assignments to Left and Top properties are ignored.

VB.NET behaves slightly differently, because it ignores assignments to Left and Top properties also if StartupUpPosition is equal to 3-Windows Default.

There are several ways to work around this issue. In the first and by far the simplest solution, you change the original VB6 form’s StartUpPosition to 0-Manual at design time.

If the simple fix isn’t applicable, your VB.NET code should change the property immediately before settings the Left or Top properties:

        Private Sub Command1_Click() Handles Command1.Click
            Dim frm As New GraphicsForm
            '## InsertStatement frm.StartPosition = FormStartPosition.Manual
            frm.Left = 0: frm.Top = 0
            frm.Show()
        End Sub

The third available solution is that you assign the Left and Top properties in the form’s Load event handler rather than before invoking the Show method:

        Private Sub Form_Load()
            Me.Left = 0: Me.Top = 0
        End Sub

 

Previous | Index | Next