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

  • Thread starter Thread starter Joe Duchtel
  • Start date Start date
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
 
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).
 
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
 
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
 
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
 
Back
Top