Previous | Index | Next 

[PRB] Form_Load events in default form instances

When using a default form instance the behavior of migrated code differs from VB6: under VB6, the Load event for such forms fire only once; conversely, in migrated .NET code the Load event fires any time the form is showed.

If preserving the original VB6 behavior is crucial, you should add a boolean flag to discern between the first and subsequent event invocation, as in this example:

    ' VB.NET
    Private m_FormShowed As Boolean

    Private Sub Form_Load() Handles MyBase.Load
	    If m_FormShowed Then Exit Sub
	    m_FormShowed = True
	    ' ...
    End Sub
    // C#
    private bool m_FormShowed;

    private void Form_Load() 
    {
	if (m_FormShowed) 
	     return;
          m_FormShowed = true;
	// ...
    }

 

Previous | Index | Next