Form Preloading???

  • Thread starter Thread starter Pepi Tonas
  • Start date Start date
P

Pepi Tonas

Hi all,

I have an application with a main window full of buttons. Where each
buttons opens a new form that deals with different portions of the
application.

This is not an MDI application, the main window remains open in the
background and all sub windows are opened with .ShowDialog().

To open these windows, I use the following code on the main form:

Private Sub btnNotas_Click( . . . ) Handles btnNotas.Click
Dim frmNotas As New frmNotas
frmNotas.ShowDialog()
frmNotas.Activate()
End Sub


On the child form, to close (leave) I use:

Private Sub btnReturn_Click( . . . ) Handles btnReturn.Click
Me.Close()
End Sub

This forms take time to load and the user sometimes feels the program
may be unresponsive.

Is there a way to preload these child forms at start up, without
showing them until the user clicks on the assigned button.

If so, what would be the code used to hide it and return control to
the main form.

Right as I am doing it, I am creating a new instance of the form every
time the buttons are clicked and destroying it when user returns to
the main form.

Thanks in advance....
 
solex said:
aform = New MyForm
aform.Hide()

Dim mNotas As frmNotas

Sub frmMain_Load()
mNotas = New frmNotas
End Sub

Private Sub btnNotas_Click(...) Handles btnNotas.Click
mNotas.ShowDialog()
mNotas.Activate()
End Sub


Similar to what solex described briefly but gives a better understanding...and
yes, this is off top of my head, will not work as is...but shows how it can work.

Mythran
 
Pepi Tonas said:
Private Sub btnNotas_Click( . . . ) Handles btnNotas.Click
Dim frmNotas As New frmNotas
frmNotas.ShowDialog()
frmNotas.Activate()
End Sub

frmNotas.Activate() doesn't make sense because the Form is invisible when
Activate is executed.

This forms take time to load and the user sometimes feels the
program may be unresponsive.

Why not display an hourglass?
 
* Pepi Tonas said:
I have an application with a main window full of buttons. Where each
buttons opens a new form that deals with different portions of the
application.

This is not an MDI application, the main window remains open in the
background and all sub windows are opened with .ShowDialog().

To open these windows, I use the following code on the main form:

Private Sub btnNotas_Click( . . . ) Handles btnNotas.Click
Dim frmNotas As New frmNotas
frmNotas.ShowDialog()
frmNotas.Activate()

The form will be activated automatically, you don't need the line above.
On the child form, to close (leave) I use:

Private Sub btnReturn_Click( . . . ) Handles btnReturn.Click
Me.Close()
End Sub

Instead of closing the form, call its 'Hide' method. I would not
"preload" the forms, that's not even prossible in an easy way. After
showing the form for the 1st time, just hide it and show the same
instance again.
 
* "Armin Zingler said:
frmNotas.Activate() doesn't make sense because the Form is invisible when
Activate is executed.

It's closed in the sample above.
 
Doesn't the control of the program go to the form when you call the
ShowDialog method?
 
Back
Top