• Advertisement

• ### Popular Now

• 12
• 12
• 9
• 10
• 13
• Advertisement
• Advertisement
• Advertisement

# [.net] Vb 6.0 to VB.Net conversion problem w.r.t FormActivated event

This topic is 2810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

We are converting a Visual Basic 6.0 application to vb.net 2008 and are having an issue, while executing the code under “form activated event”. There is a difference in behavior between form.activate in Visual Basic 6.0 and form.activated in vb.net. In Visual Basic 6.0, the Activate event was raised only when switching between forms in the application; in Visual Basic .NET, the Activated event also is raised in case of showing messagebox and when switching from other applications.(by msdn)

In vb6 application the purpose to use form activate event is, to execute some code when forms become active. In our application forms are loaded, hide and show in different flows. So whenever this form is shown from hide state or any of its child form return focus to it, we need to reflect different changes in the application to the specific form controls.

* For example user changes its application preferred language.
* As the application is huge, so shifting logic to other place with respect to the current scenario might solve the problem for the current form but then I have to re think it for all other forms (which is very hectic and more or less not feasible).

In the migration process it is required to make as little changes in the existing code execution hierarchy. So we need a similar behavior like form.activate in vb6.0 with some other event or restrict some functionality of Activated event in vb.net.

#### Share this post

##### Share on other sites
Advertisement
When I used Form_Activate it fired on program switching, load but I didn't test for hide/show. This code should fire on any kind of "activation" and it will only fire once every 500 ms.

   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated, Me.Shown, Me.Invalidated        Static runOnce As Long        ' Make sure this hasn't fired in the last 500ms        If TimeOfDay.Ticks > runOnce + 5000000 Then            Debug.Print("I am doing stuff once but I should be fool proof!: " + TimeOfDay.Ticks.ToString)            ' Make sure we store the last time it was run            runOnce = TimeOfDay.Ticks        End If    End Sub

#### Share this post

##### Share on other sites

• Advertisement