473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Close Form

Hello everybody,

I have a Menu form where I have a button.

The user should click the button and the program should open another
form call register form. I want that when the program show the register
form, the menu form will close or hiden.

I use the close () method, but it close everything (both forms) but if i
use hide() method.. even when I close all the forms using the X button
in the right top corner, it seems to me that the program is still
running in the background, because I need to manually click on the stop
button that is in C# express 2005

Is there a way to close just the menu form???

In VB6 all I needed to do is call registerform.show()
and menuform.close()

Can somebody help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jun 7 '06 #1
2 2778
When the main form (startup form) is closed the application will terminate,
as you have found. You'll need to architect your application in such a way
to allow the main form to stay "alive" for the duration of your application.

--
Tim Wilson
..NET Compact Framework MVP

"Claudia Fong" <cd********@yahoo.co.uk> wrote in message
news:OJ**************@TK2MSFTNGP05.phx.gbl...
Hello everybody,

I have a Menu form where I have a button.

The user should click the button and the program should open another
form call register form. I want that when the program show the register
form, the menu form will close or hiden.

I use the close () method, but it close everything (both forms) but if i
use hide() method.. even when I close all the forms using the X button
in the right top corner, it seems to me that the program is still
running in the background, because I need to manually click on the stop
button that is in C# express 2005

Is there a way to close just the menu form???

In VB6 all I needed to do is call registerform.show()
and menuform.close()

Can somebody help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Jun 7 '06 #2
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:ui**************@TK2MSFTNGP04.phx.gbl...
When the main form (startup form) is closed the application will
terminate, as you have found. You'll need to architect your application in
such a way to allow the main form to stay "alive" for the duration of your
application.


This is the default behaviour, but it can be changed by using a class
derived from the ApplicationContext class. Here's an example of the
Program.cs file that does what the OP wants, i.e. Form1 is displayed when
the program starts, then when Form1 is closed Form2 is displayed, and when
Form2 is closed the program exits.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
class MyApplicationContext : ApplicationContext
{
public MyApplicationContext()
{
Form1 f1 = new Form1();
f1.FormClosing += new FormClosingEventHandler(form1_FormClosing);
f1.Show();
}
void form1_FormClosing(object sender, FormClosingEventArgs e)
{
Form f2 = new Form2();
// Next line is crucial. When ApplicationContext.MainForm is closed then the
program will exit.
MainForm = f2;
f2.Show();
}
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
// Note you run an instance of your ApplicationContext, NOT your main form.
Application.Run(new MyApplicationContext());
}
}
}

Chris Jobson
Jun 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the...
1
by: Jules Winfield | last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:...
2
by: Chien Lau | last post by:
Hi, At a certain point in my application, I have access to a Form object. I want to close that form: form.Close(); There are any number of reasons why this form might not close. A common...
7
by: Alice | last post by:
Hi, In my program, the user can navigate to many different forms. When they go to the next form, I want the form they have left to close. However, the forms aren't closing. Can anyone tell me...
5
by: Stan Sainte-Rose | last post by:
Hi, Which event is called when the user click on the close window icon (X) ? I want, when he clicks on this icon, to display a message before closing the form. If he replys by No, I don't want to...
6
by: Tom | last post by:
Is there ANY easy way to close a MDI Child form in the middle of it's load? For instance, during the Load event I find a need to close the form (for whatever reason - maybe the user isn't ready for...
5
by: AP | last post by:
IS there a way to run a procedure if the users close access directly rather than closing a menu screen that I have built? There is an event that works on close for this form, but it doesnt seem to...
6
by: scott | last post by:
I guess this is a simple one but I can't seem to get it to work. I want to refresh an open form "onClose" of another. I have a Close button on a form which has User Details on it. If I update...
3
by: rdemyan via AccessMonster.com | last post by:
I need help with code to close two forms at the same time, FormA and FormB. I need code that can be used from either form and needs to work with both a 'Close' button on each form as well as if the...
1
by: dan.c.roth | last post by:
oForm.Close() vs this.Close() in a modal dialog. oFrom.Close() calls Form.Dispose() but this.Close() ,say in the click event of the Form, does not. I can think of the reason for this but is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.