Me.Hide()

  • Thread starter Thread starter SLE
  • Start date Start date
S

SLE

Hi there,

The Main() of a Windows Forms application launches a dummy, invisible form:

Sub Main()
Dim f As FormFoo

Try
f = New FormFoo
f.ShowDialog()

'
'-- perform some post-processing
'

Catch ex As Exception
...
Finally
If Not IsNothing(f) Then
f.Dispose()
End If
End Try
....
End Sub

Public Class FormFoo
Inherits System.Windows.Forms.Form
...
Private Sub FormFoo_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
With Me
If .Visible Then
.Hide()
End If
End With
End Sub
End Class

This works as expected, however when the user issues a logoff or shutdown,
my application ends (normally) but the system won't initiate the
shutdown/logoff :-|

Any clues?


Thanks,
 
SLE said:
Hi there,

The Main() of a Windows Forms application launches a dummy, invisible form:

Sub Main()
Dim f As FormFoo

Try
f = New FormFoo
f.ShowDialog()

'
'-- perform some post-processing
'

Catch ex As Exception
...
Finally
If Not IsNothing(f) Then
f.Dispose()
End If
End Try
...
End Sub

Public Class FormFoo
Inherits System.Windows.Forms.Form
...
Private Sub FormFoo_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
With Me
If .Visible Then
.Hide()
End If
End With
End Sub
End Class

This works as expected, however when the user issues a logoff or shutdown,
my application ends (normally) but the system won't initiate the
shutdown/logoff :-|

Any clues?


Thanks,

Problem is hiding a form does not close it. If you are going to have a
bunch of these around, make an arraylist, and add each form instance to
it. Then in your form.closing event iterate the array list, and close
all the forms, and then allow the main form closing event sub to exit.

- Lee
 
Lee Gillie said:
Problem is hiding a form does not close it. If you are going to have a
bunch of these around, make an arraylist, and add each form instance to
it. Then in your form.closing event iterate the array list, and close
all the forms, and then allow the main form closing event sub to exit.

There is only a single form running invisibly. I have tried to add a
Me.Close() to the FormFoo_Closing() event but that does not change the
behaviour (i.e. appliction is terminated but logoff/shutdown stalls).

Any other ideas?
 
There is only a single form running invisibly. I have tried to add a
Me.Close() to the FormFoo_Closing() event but that does not change the
behaviour (i.e. appliction is terminated but logoff/shutdown stalls).

Any other ideas?

Is FormFoo the invisible one or the main form?
Once you get to the closing event, close is already occurring.

How ever your program exits it needs to do something like
InvisibleForm.Close before it goes away. If there is a main form, then
the mainform.closing event would be a good place to put this.

A windows application will not exit until all the forms have closed.
This is what is keeping your users from logging off.
Check task manager, and you will see processes running your program are
still alive and running. There may be a number of them right now if you
have run your program several times since last logon.

- Lee
 
Back
Top