Execute code after form is visible

E

Ender

I am using a hosted ActiveX control within a Windows Forms
application. I can not properly activate the ActiveX control because
the control's GUI can be initialized only when the form has completed
the loading of it's GUI.

How can I get the control to activate properly? I have tried to use
the Activated event in the Winform, however, this does not appear to
work. I have also tried initializing the ActiveX control during the
VisibleChanged, Enter and GotFocus events, none of which appear to
work.

Does anyone have a good way approach to executing a code AFTER the GUI
has been initialized? Note, this also uses a ShowDialog, and not Show
to display the Winform.

I have tried the google groups without much luck.

Thanks
Endymion Keats
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Ender) scripsit:
I am using a hosted ActiveX control within a Windows Forms
application. I can not properly activate the ActiveX control because
the control's GUI can be initialized only when the form has completed
the loading of it's GUI.

How can I get the control to activate properly? I have tried to use
the Activated event in the Winform, however, this does not appear to
work. I have also tried initializing the ActiveX control during the
VisibleChanged, Enter and GotFocus events, none of which appear to
work.

Does anyone have a good way approach to executing a code AFTER the GUI
has been initialized? Note, this also uses a ShowDialog, and not Show
to display the Winform.

Try this (in the form's 'Load' event handler:

\\\
....
Me.Show()
' Maybe Me.Refresh().
DoSomethingWithTheControl()
///
 
P

Palo Mraz

Does anyone have a good way approach to executing a code AFTER the GUI
has been initialized? Note, this also uses a ShowDialog, and not Show
to display the Winform.

I'd suggest the Application.Idle event:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
...
AddHandler System.Windows.Forms.Application.Idle, AddressOf
Me.InitializeControl
...
End Sub

Private Sub InitializeControl(ByVal sender As Object, ByVal e As EventArgs)
Static Initialized As Boolean
If Not Initialized Then
Initialized = True
' Initialize your ActiveX control here.
End If
End Sub

Happy new year!

Palo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top