473,785 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.sh ow()
and menuform.close( )

Can somebody help me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jun 7 '06 #1
2 2803
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********@yah oo.co.uk> wrote in message
news:OJ******** ******@TK2MSFTN GP05.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.sh ow()
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)ROGE RS(PERIOD)COM> wrote in message
news:ui******** ******@TK2MSFTN GP04.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 ApplicationCont ext 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.Collecti ons.Generic;
using System.Windows. Forms;
namespace WindowsApplicat ion1
{
class MyApplicationCo ntext : ApplicationCont ext
{
public MyApplicationCo ntext()
{
Form1 f1 = new Form1();
f1.FormClosing += new FormClosingEven tHandler(form1_ FormClosing);
f1.Show();
}
void form1_FormClosi ng(object sender, FormClosingEven tArgs e)
{
Form f2 = new Form2();
// Next line is crucial. When ApplicationCont ext.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.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
// Note you run an instance of your ApplicationCont ext, NOT your main form.
Application.Run (new MyApplicationCo ntext());
}
}
}

Chris Jobson
Jun 8 '06 #3

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

Similar topics

6
2744
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 work. Nota() - opens new window. fechaNota() - closes the window opened by Nota() here is the code.
1
2105
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: foreach(MyForm form in AllMyForms){ form.Close(); } Application.Exit(); The OnClosing method is overridden in MyForm. If the user has made changes to his form, this method asks him if he'd like to: a) save his changes b) forget changes...
2
4992
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 reason might be that the user answered "No" when the form's OnClosing() override asked him "Are you sure you want to close this form?"
7
2519
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 what I'm doing wrong? Here is a sample snippet of code where the user can return to the main form while simultaneously closing the previous form.
5
11074
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 close the form. Thks for your help Stan
6
6652
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 it yet, or it displays another form and they hit cancel). In any event, I need to be able to cause that MDI Child form to close. Just sticking Me.Close in there won't work, generates an error (note however, that on a NON-MDI form this seems to...
5
7448
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 run if the form is open and the suer just closes access all together, is there a way around this? Thanks
6
6993
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 the data on that from, I want it to automatically refresh the details which are shown on an open form. I was going to use the default access code DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
3
4433
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 user clicks the 'X' in the control box. I have a function, IsObjectOpen, that can be used to check if a form is open. The function is used as follows: X = IsObjectOpen(FormName,2)
1
3871
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 this documented and if so can someone give me the reference. And is this true for .net 1 and 2. Thanks
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.