I am writing a new C# 2010 desktop applicaton. I am using some of the exsting code in another C# 2010 application to start the new application since I will be using alot of existing code that works. I basically want to have a desktop form where the user can enter some data and return to the statement after 'Application.Run(new RejectForm());' listed below.
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RejectForm());
}
I would like to have the data that was entered in the form be available to the application at this point.
Thus can you tell me the following:
1. How can I return to the location right after the Application.Run(new RejectForm()); statement?
2. How can i have the values that were entered on the windows form be available for the rest of the application to
access from this point?
Loading
VulpesPosted Jun 12, 2013, 4:41 AM
The execution path of the code will then revert to the statement after Application.Run() in your Main method.
Incidentally, despite the name, all Application.Exit does is to close all open forms and cause Application.Run to return. It doesn't cause the application itself to end unless there are no more statements in the Main() method after Application.Run.
Closing the main form (i.e. the form specified in Application.Run) has the same effect as calling Application.Exit.
Sie StePosted Jun 11, 2013, 11:35 PM
Would I place the application.exit as one of the last statements in the program to run?
Also after the user hits the submit button, how can I have the process return to the main flow of logic in the main method?
VulpesPosted Jun 11, 2013, 7:29 PM
Sie StePosted Jun 11, 2013, 6:16 PM
"Either close the main form (i.e. RejectForm) or call Application.Exit() to return to that location."?
VulpesPosted Jun 11, 2013, 5:29 PM
2. I'd give the Program class (which contains the Main() method) some internal static fields to contain the data you want to be available to the rest of the application (presumably console app thereafter?). For example:
static class Program
{
internal static string globalString;
internal static int globalInt;
[STAThread]
static void Main()
{
// blah
}
}
The main form should then set these fields before it's closed or Application.Exit is called. For example:
Program.GlobalString = "Whatever";
Program.GlobalInt = 42;