473,387 Members | 1,705 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,387 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 2777
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.