Closing a Hidden Form

E

Ed Bitzer

Need help closing my program. I .show() an instruction form2 for a few
seconds using a timer and then hiding the form so that the routine may
be used later if necessary. However when I shut the program down the
Windows Task Manager still shows a copy of my program running - and by
trial and error it is the creation of this "hiden" that is the cause.
In the Closing subroutine of the main form1 I have tried to
form2.close and even form2.dispose but with no joy.

Appreciate some help,

Ed
 
P

PJ6

Make the main form an MDI Parent and the second a child of that parent. You
don't need to display a child form within its parent IIRC but you may want
to re-evaluate your design to see if the user might like that better.

Paul
 
T

Teemu

Ed Bitzer said:
Need help closing my program. I .show() an instruction form2 for a few
seconds using a timer and then hiding the form so that the routine may
be used later if necessary. However when I shut the program down the
Windows Task Manager still shows a copy of my program running - and by
trial and error it is the creation of this "hiden" that is the cause.
In the Closing subroutine of the main form1 I have tried to
form2.close and even form2.dispose but with no joy.

At least in VB2005 and VB2008 there is a setting "Shutdown mode" in
project's properties. There are two options: "When startup form closes" and
"When last form closes".

If the first option is selected then your program should quit when Form1 is
closed if it is your program's startup form.

-Teemu
 
A

Armin Zingler

Ed said:
Need help closing my program. I .show() an instruction form2 for a few
seconds using a timer and then hiding the form so that the routine may
be used later if necessary. However when I shut the program down the
Windows Task Manager still shows a copy of my program running - and by
trial and error it is the creation of this "hiden" that is the cause.
In the Closing subroutine of the main form1 I have tried to
form2.close and even form2.dispose but with no joy.

Appreciate some help,


"Application Framework" is enabled? What's the startup object? If you have a
Sub Main, do you call ShowDialog or Application.Run?
Post the exact code creating, showing and destroying Form2.


Armin
 
E

Ed Bitzer

Armin Zingler said:
"Application Framework" is enabled? What's the startup object? If
you have a Sub Main, do you call ShowDialog or Application.Run?
Post the exact code creating, showing and destroying Form2.


Armin

Armin - here is the code:

Dim Progress As New frmProgressNotice

Under my Dial Sub
timeinsec = timedelay
Progress.Show()
Timer2.Start()
While exitFlag = False
Application.DoEvents()
End While

In the Timer2 Sub
If NewTime = 0 Then
Timer2.Enabled = False
Progress.Hide()
End If

And finally in my Form1.Closing
Progress.Close()
Progress.Dispose()

Of course the latter did nothing.

Ed
 
E

Ed Bitzer

Teemu said:
At least in VB2005 and VB2008 there is a setting "Shutdown mode" in
project's properties. There are two options: "When startup form
closes" and "When last form closes".

If the first option is selected then your program should quit when
Form1 is closed if it is your program's startup form.

-Teemu

Teemu, I am working under the free Visual Studio .NET 2003 using
VB2003. I have searched the project properties and cannot find such
an option, only the Startup Object under the Application tab (side
list). That certainly looks like what I need.

Ed
 
E

Ed Bitzer

PJ6 said:
Make the main form an MDI Parent and the second a child of that
parent. You don't need to display a child form within its parent
IIRC but you may want to re-evaluate your design to see if the user
might like that better.

Paul
Paul: I do not see why I should have to use an MDI Parent for a
simple program that opens another form but rather than closing hides.
I have other forms that open with ShowDialog and they also cause no
problems.

Ed
 
T

Teemu

Teemu, I am working under the free Visual Studio .NET 2003 using
VB2003. I have searched the project properties and cannot find such an
option, only the Startup Object under the Application tab (side list).
That certainly looks like what I need.

It is in Application tab at least in VB2005 and VB2008 so maybe it was a new
feature in VB2005.

-Teemu
 
E

Ed Bitzer

Teemu, sorry I am using Visual Basic 2008 Express Edition - mind
wondered as usual.

Ed
 
T

Teemu

Ed Bitzer said:
Teemu, sorry I am using Visual Basic 2008 Express Edition - mind
wondered as usual.

Ed

Then you should see that option in Project's properties under Application
tab. If you have a console application then that option is disabled but you
can see it.

Here is a picture:
http://www.flickr.com/photos/rwindsor/1163425512/
It is above the red square.

But the default setting is "When startup form closes" so maybe there is
another problem?

-Teemu
 
E

Ed Bitzer

Ed

Then you should see that option in Project's properties under
Application tab. If you have a console application then that option
is disabled but you can see it.

Here is a picture:
http://www.flickr.com/photos/rwindsor/1163425512/
It is above the red square.

But the default setting is "When startup form closes" so maybe there
is another problem?

-Teemu

Teemu, the screen displayed under the main menu's Project and then
"myprograms" Properties using Visual Basic 2008 Express Edition is
totally different than that you show. Might the difference be in my
use of the Express Edition.

Ed
 
T

Teemu

Ed Bitzer said:
Teemu, the screen displayed under the main menu's Project and then
"myprograms" Properties using Visual Basic 2008 Express Edition is totally
different than that you show. Might the difference be in my use of the
Express Edition.

That picture is probably from VB2005 but my view in VB 2008 Express Edition
is almost the same. Note that the picture is only a portion of the whole
window.

-Teemu
 
A

Armin Zingler

Ed said:
Armin - here is the code:

Dim Progress As New frmProgressNotice

Under my Dial Sub
timeinsec = timedelay
Progress.Show()
Timer2.Start()
While exitFlag = False
Application.DoEvents()
End While

In the Timer2 Sub
If NewTime = 0 Then
Timer2.Enabled = False
Progress.Hide()
End If

And finally in my Form1.Closing
Progress.Close()
Progress.Dispose()

Of course the latter did nothing.


Why do you use DoEvents? It's not necessary. Either use Show or ShowDialog.
Again the question: What startup object do you have in the project
properties? Do you have a sub main? Where is your "Dial Sub" called?


Armin
 
F

Family Tree Mike

Ed Bitzer said:
Armin - here is the code:

Dim Progress As New frmProgressNotice

Under my Dial Sub
timeinsec = timedelay
Progress.Show()
Timer2.Start()
While exitFlag = False
Application.DoEvents()
End While

In the Timer2 Sub
If NewTime = 0 Then
Timer2.Enabled = False
Progress.Hide()
End If

And finally in my Form1.Closing
Progress.Close()
Progress.Dispose()

Of course the latter did nothing.

Ed


It shouldn't be that complicated. In my project I used form1.vb and
form2.vb, where form2 is equivalent to your frmProgressNotice. form1 is the
startup form. form2 has no code in it, as there does not need to be any.
Here is the code for form1.vb

Form1 has a button on it to unhide the form2 instance.

I'm not seeing any zombie processes as you describe in the original post.


Public Class Form1
Private progress As New Form2
Private WithEvents timer2 As New Timer

Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
progress.Show()
timer2.Interval = 2000
timer2.Start()
End Sub

Private Sub timer2_Tick _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles timer2.Tick
progress.Hide()
timer2.Stop()
End Sub

Private Sub Unhide_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Unhide.Click
progress.Visible = True
End Sub
End Class
 
E

Ed Bitzer

Teemu said:
That picture is probably from VB2005 but my view in VB 2008 Express
Edition is almost the same. Note that the picture is only a portion
of the whole window.

-Teemu

Teemu,

Thanks for sticking with this dummy. I just found those options by
finding the Application dialog windows had a scroll bar and scrolling
down. However I tried both unsuccessfully. The program closes but
something is leaving trash identified by the program.exe displaying
under the Windows Task Manager. I need to set up a simple test bed
with just two windows and play with a timer to display to control the
duration of the seconds display and determine what I am doing wrong.

Thanks,
Ed
 
E

Ed Bitzer

It shouldn't be that complicated. In my project I used form1.vb and
form2.vb, where form2 is equivalent to your frmProgressNotice.
form1 is the startup form. form2 has no code in it, as there does
not need to be any. Here is the code for form1.vb

Form1 has a button on it to unhide the form2 instance.

I'm not seeing any zombie processes as you describe in the original
post.


Public Class Form1
Private progress As New Form2
Private WithEvents timer2 As New Timer

Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent()
call.
progress.Show()
timer2.Interval = 2000
timer2.Start()
End Sub

Private Sub timer2_Tick _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles timer2.Tick
progress.Hide()
timer2.Stop()
End Sub

Private Sub Unhide_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
_
Handles Unhide.Click
progress.Visible = True
End Sub
End Class

Mike,
This is not my day - can't even get your code to kill the second firm
after 2 seconds. Armin is also correct that I do not need the
doevents. I have to hit the sack, still recovering from bypass
surgery and now I am starting to think that plumbing job also effect
my brain. I'll go back to basics in the morning with a simple test
bed trying Mike's code with a cut and paste so I do not screw it up.
Thanks again.

Ed
 
E

Ed Bitzer

Mike Armin and Teemu:

Got everything working this morning. First simply duplicated Mike's
code and of course this morning it worked properly. Then reexamined
my own code and found several simple mistakes the biggest of which was
a duplication of the Progress as New Form2. Will try to take a little
time today to determine just how that bad code leaves trash behind but
incentive will be less with so many gaps in my coding knowledge to
just code correctly.

Thanks again - an old retired guys dialer now works properly.

Ed
 
P

PJ6

Ed Bitzer said:
Paul: I do not see why I should have to use an MDI Parent for a simple
program that opens another form but rather than closing hides. I have
other forms that open with ShowDialog and they also cause no problems.

MDI works well for applications that have more than one form; it's
specifically designed to give you what you want even if you only have two.
You don't have to use MDI, it's just easier.

Good luck,
Paul
 
T

Teemu

MDI works well for applications that have more than one form; it's
specifically designed to give you what you want even if you only have two.
You don't have to use MDI, it's just easier.

MDI is quite old approach now if you look modern applications. Besides MDI
Children look terrible in Windows Vista because it doesn't render them with
Aero theme.

-Teemu
 
P

PJ6

Teemu said:
MDI is quite old approach now if you look modern applications. Besides MDI
Children look terrible in Windows Vista because it doesn't render them
with Aero theme.

Ahh well my thick client UI development skill is a bit dated now, everyone
wants web.

I disabled themes as a matter of course in my applications when XP came out
("this is a business application, not a Fisher Price toy") so Aero being
unpredictable wouldn't have bothered me in the least. :)

Paul
 

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