How to close Form1 from Form2?

S

Steve Howard

I want to close my initial form - Form1 - from my main menu form - Form2.
The object of this is when I close the Main Menu I want the entire
application to close - not minimise, pause or in some other way remain
active in memory. I want it to close.


Which means I also recognise that my attempt to close Form1 as Form2 is
closing is very likely the wrong approach to take, so please correct my
approach if that is required.


To put it another way, while in Form2 I want to kill the entire application
when Form2 is closed. How should I do this?


Thanks in advance,


Steve
 
G

Guest

Have Form1 subscribe to an event of Form2 to tell it that it's been closed,
then close itself in the event handler.

-Chris
 
S

Steve Howard

Have Form1 subscribe to an event of Form2 to tell it that it's been
closed, then close itself in the event handler.


OK I should have mentioned I am a beginner here...

I had a look at event subscription, and somehow it seems unnecessarily
complex. Before I go off down that route, it occurs to me that I am probably
approaching this all wrong.

What I have is an application that will do the following

1, Open with a splash screen
2, Move automatically, or on users click on-screen (5 seconds, or click,
whichever is first) to a main menu
3, Move to one of several content sections when a selection is made from the
menu.


So right now I add a new instance of MainMenu form at the start, than add
Introduction or whatever when the user clicks a menu option.


What happens is that I end up with several forms on screen, each acting like
a separate process - they show up as such, although they are clearly linked
as parent/child or whatever.


It seems to me that sometime I read something about managing forms that was
more elegant than this, but I cannot find it. I suspect that if I can locate
a more elegant method for managing my forms, my original question becomes
moot.


Make sense?

If so, where can I find information about proper form handling. I looked on
MSDN and elsewhere but I guess I am not searching for the right terms.

TIA

Steve
 
G

Guest

Search for "MultiForm framework". I did an MSDN article on it in C# (a
rewrite of an old eVB article I did for DevBuzz). It was rewritten in
VB.NET and is posted on OpenNETCF's site. It's not the end-all of fomr
managing models - I like it for models where you want a "back" analogy, but
it's food for thought.

-Chris
 
S

Steve Howard

Search for "MultiForm framework". I did an MSDN article on it in C# (a
rewrite of an old eVB article I did for DevBuzz). It was rewritten in
VB.NET and is posted on OpenNETCF's site. It's not the end-all of fomr
managing models - I like it for models where you want a "back" analogy,
but it's food for thought.


Looks like this is it

http://msdn.microsoft.com/mobility/...ary/en-us/dnnetcomp/html/netcfuiframework.asp


I think this is the article I found before. I need to digest it overnight.
More questions tomorrow, no doubt.

Thanks Chris!


Steve
 
S

Steve Howard

Looks like this is it

http://msdn.microsoft.com/mobility/...ary/en-us/dnnetcomp/html/netcfuiframework.asp


I think this is the article I found before. I need to digest it overnight.
More questions tomorrow, no doubt.


After a night's sleep and little more reading around the subject, I am not
certain how this helps me as a beginner in c#. I think this is mainly
becuase a lot of what you and others have to say is over my head. I get the
general principle of a stack (deck of cards) that helps track form usage,
it's the more OOP stuff that I still don't have a good grasp of
(inheritance, classes etc).

Let's assume I am going to continue to try to get a grasp on the Multiform
Framework, but for the moment I want to return to my original question.

I have been using what appears to be a standard method to open new forms ...

//new instance of Main Menu form

myForm = new mainMenu();

//Show it

myForm.Show();



On my development PDA I have Wisebar Advanced installed. When I open my
form this way, it appears in the titlebar as a second process ... so I have
two active icons for my application, one for the initil form and one for the
main menu. When I add another form (make a menu selection) I get a third
icon. When I look at Sytem>Memory>Running Programs I also see two processes
.... My Application and Main Menu. Obviously I want only a single process to
be visible. How do I remedy that?



TIA





Steve
 
C

Chris Tacke, eMVP

It's not showing processes, it's simply showing the titles of top-level
Forms. Before showing Form2, set Form1's Text to "".

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
S

Steve Howard

It's not showing processes, it's simply showing the titles of top-level
Forms. Before showing Form2, set Form1's Text to "".


Aaaargh!!!



No wonder I couldn't find a solution.

Obviously the way to avoid it in the first place is not to set the Text
property at all, yet it is useful to set in for development use.

Thanks again!!!


Steve
 

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