MoSlo
MoSlo

Reputation: 2870

Form load Event fires twice, using Interop Forms Toolkit

I've been following a codeproject article on using the interop forms toolkit (basically a way for developers to slowly upgrade their VB6 projects to .net by allowing .net components run in VB6)

http://www.codeproject.com/KB/vb-interop/VB6InteropToolkit2.aspx

While the .NET form is working fine in all other testing projects and environments, I've found that the Form_load event is actually firing twice once it's in executing in the VB6 runtime.

Not only annoying, its forcing my initialization code to execute twice (causing all kind of problems on the second run).

Is there any explanation as to why this is happening (I'd like to understand the reason)?

Is there anything better way to work-around this apart from

 If (runBefore = True) Then

Upvotes: 2

Views: 2011

Answers (2)

widgets19
widgets19

Reputation: 1

hi i've tried this and it works..

i put it in form_activate. basically to test if the form is already loaded. if it is, then unload it. I use i as counter.

Private Sub Form_Activate()

Dim TestForm As Form
i = 0
For Each TestForm In Forms
    If TestForm.Name = "frmStocks" Then i = i + 1
    If i = 2 Then Unload Me
Next TestForm

End Sub

Upvotes: 0

xpda
xpda

Reputation: 15813

It's possible for this occur if you implicitly begin loading a form by accessing a public variable in the form from another module, then explicitly .show the form before the loading is complete.

Upvotes: 2

Related Questions