Click here to Skip to main content
15,904,934 members
Home / Discussions / C#
   

C#

 
GeneralRe: converting string to date Pin
sachees12313-Apr-09 1:44
sachees12313-Apr-09 1:44 
GeneralRe: converting string to date Pin
Colin Angus Mackay13-Apr-09 1:46
Colin Angus Mackay13-Apr-09 1:46 
GeneralRe: converting string to date Pin
sachees12313-Apr-09 1:56
sachees12313-Apr-09 1:56 
GeneralRe: converting string to date Pin
Roberto Ho13-Apr-09 2:11
Roberto Ho13-Apr-09 2:11 
GeneralRe: converting string to date Pin
Colin Angus Mackay13-Apr-09 2:15
Colin Angus Mackay13-Apr-09 2:15 
GeneralRe: converting string to date Pin
Colin Angus Mackay13-Apr-09 2:12
Colin Angus Mackay13-Apr-09 2:12 
GeneralRe: converting string to date Pin
sachees12313-Apr-09 2:36
sachees12313-Apr-09 2:36 
GeneralRe: converting string to date Pin
Colin Angus Mackay13-Apr-09 2:44
Colin Angus Mackay13-Apr-09 2:44 
GeneralRe: converting string to date Pin
sachees12313-Apr-09 2:53
sachees12313-Apr-09 2:53 
GeneralRe: converting string to date Pin
PIEBALDconsult13-Apr-09 4:06
mvePIEBALDconsult13-Apr-09 4:06 
AnswerRe: converting string to date Pin
ramzg13-Apr-09 3:36
ramzg13-Apr-09 3:36 
Questionexecute one application from another dummy application Pin
NetQuestions13-Apr-09 0:29
NetQuestions13-Apr-09 0:29 
AnswerRe: execute one application from another dummy application Pin
Colin Angus Mackay13-Apr-09 0:37
Colin Angus Mackay13-Apr-09 0:37 
GeneralRe: execute one application from another dummy application Pin
NetQuestions15-Apr-09 4:17
NetQuestions15-Apr-09 4:17 
Questionhow to get link download file like IDM ? Pin
kimlongap13-Apr-09 0:18
kimlongap13-Apr-09 0:18 
Questionhave a child while parent is not accesible Pin
cppwxwidgetsss12-Apr-09 23:52
cppwxwidgetsss12-Apr-09 23:52 
AnswerRe: have a child while parent is not accesible Pin
Vikram A Punathambekar13-Apr-09 0:10
Vikram A Punathambekar13-Apr-09 0:10 
GeneralRe: have a child while parent is not accesible Pin
Fired.Fish.Gmail13-Apr-09 6:01
Fired.Fish.Gmail13-Apr-09 6:01 
GeneralRe: have a child while parent is not accesible Pin
cppwxwidgetsss13-Apr-09 18:25
cppwxwidgetsss13-Apr-09 18:25 
GeneralRe: have a child while parent is not accesible Pin
Fired.Fish.Gmail14-Apr-09 0:03
Fired.Fish.Gmail14-Apr-09 0:03 
GeneralRe: have a child while parent is not accesible Pin
cppwxwidgetsss14-Apr-09 1:12
cppwxwidgetsss14-Apr-09 1:12 
GeneralRe: have a child while parent is not accesible Pin
Vikram A Punathambekar14-Apr-09 7:27
Vikram A Punathambekar14-Apr-09 7:27 
Questionresolving lag connection to remote server? Pin
[c]amilo12-Apr-09 22:28
[c]amilo12-Apr-09 22:28 
QuestionClosing a form Pin
Deepali Khalkar12-Apr-09 22:27
Deepali Khalkar12-Apr-09 22:27 
AnswerRe: Closing a form Pin
Juan1R12-Apr-09 22:58
Juan1R12-Apr-09 22:58 
The reason why the application exits automatically is that the entry point for it is located in a class usually called Program.cs that has the following code:

static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

The last line (Application.Run(new Form1())), starts a message loop that ends as soon as the main form is closed (new Form1()), what causes the end of the application.

To prevent the application from exiting I've found two possible solutions based on your original idea:

1. The first one is not to close the main form but to hide it:

private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
this.Hide();
}

2. The second is to invoke the Application.Run() overload that doesn't take a Form as parameter but an ApplicationContext. This object (that always exist), implements an overridable method called OnMainFormClosed() that is responsible of shutting down the application when the main form is closed. To prevent this from happening, you can derive a new class from it that substitutes the original method by another that does nothing:

//New class.
class ApplicationContextOwn : ApplicationContext {
//Overriden method does nothing
protected override void OnMainFormClosed(object sender, EventArgs e) {

}
}
static class Program {
public static ApplicationContext ac = new ApplicationContext();
///
/// The main entry point for the application.
///

[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

//The application is started using an instance of the new class.
ApplicationContext ac = new ApplicationContextNew();
ac.MainForm = new Form1();
Application.Run(ac);
}
}

Hope this helps.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.