System.Windows.Forms.Form_Load() calls Application.Exit and Formflashes?

J

Joe Duchtel

Hello -

I have a GUI that is contained in a Class which Inherits
SystemWindows.Forms.Form. The Private Sub _Load() runs a few checks
on command arguments and in some cases calls Application.Exit after an
error message is output in a MsgBox().

What I am seeing, is that the GUI briefly appears and then
disappears ... like a quick flash. Is there anything I could to avoid
that? Is there a better way to exit out of the _Load() function?

Thanks,
Joe
 
P

Patrice

You could perhaps hide the window...

If possible my personal preference would be even to avoid doing this but
instead to check command line arguments before opening the window...

(for example in MyApplication.Startup that provides a e.cancel property to
cancel the application launch).
 
S

Steve Gerrard

Joe said:
Hello -

I have a GUI that is contained in a Class which Inherits
SystemWindows.Forms.Form. The Private Sub _Load() runs a few checks
on command arguments and in some cases calls Application.Exit after an
error message is output in a MsgBox().

What I am seeing, is that the GUI briefly appears and then
disappears ... like a quick flash. Is there anything I could to avoid
that? Is there a better way to exit out of the _Load() function?

I think it is generally not a good idea to exit out of a Load event. It is
confusing to Windows. :)

A better idea is to run your tests the first time the form is Activated:

Private Sub Form1_Activated( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Activated

Static Checked As Boolean
If Not Checked Then
Checked = True
' do your checks here...
End If

End Sub
 
T

Thorsten Doerfler

Joe said:
I have a GUI that is contained in a Class which Inherits
SystemWindows.Forms.Form. The Private Sub _Load() runs a few checks
on command arguments and in some cases calls Application.Exit after an
error message is output in a MsgBox().

What I am seeing, is that the GUI briefly appears and then
disappears ... like a quick flash. Is there anything I could to avoid
that? Is there a better way to exit out of the _Load() function?

Public Shared Sub Main()
If Checked() Then
Application.Run(New Form1)
Else
MsgBox("Failed!")
End If
End Sub

In Project => Properties select 'Sub Main' as Startup Object.

Thorsten Doerfler
 
J

Joe Duchtel

I think it is generally not a good idea to exit out of a Load event. It is
confusing to Windows. :)

A better idea is to run your tests the first time the form is Activated:

Private Sub Form1_Activated( _
   ByVal sender As Object, ByVal e As System.EventArgs) _
   Handles MyBase.Activated

   Static Checked As Boolean
   If Not Checked Then
      Checked = True
      ' do your checks here...
   End If

End Sub

Hello -

I just tried this and it looks like the Activated event comes after
the Loaded. So I will get the Form visible. I guess that is not the
worst event. At least it will not flash anymore.

Thanks,
Joe
 

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