C# obtain values from windows form
-
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?
-
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?
Not sure I understand fully, but here goes. Application.Run sets up the message loop which 'runs' the form, so when the form is closed that statement ends. Normally the application terminates there as well. If you want to do some post processing create properties or retrieval methods on the form then just access them after the Run method has completed. When main() ends, so does your application.
Regards, Rob Philpott.
-
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?
static void Main(string[] args)
{
using (var f = new RejectForm())
{
if (DialogResult.OK == f.ShowDialog())
{
string someValue = f.TheValue;
}
else
{
// Cancel?
}
}
}You'd need public properties in your
RejectForm
, similar to the code below;public class RejectForm: Form
{
public string TheValue
{
get { return theValueTextBox.Text; }
}
}Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
static void Main(string[] args)
{
using (var f = new RejectForm())
{
if (DialogResult.OK == f.ShowDialog())
{
string someValue = f.TheValue;
}
else
{
// Cancel?
}
}
}You'd need public properties in your
RejectForm
, similar to the code below;public class RejectForm: Form
{
public string TheValue
{
get { return theValueTextBox.Text; }
}
}Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
How would you incorporate the code you listed above in the windows form and then have the code return to the main method?
-
How would you incorporate the code you listed above in the windows form and then have the code return to the main method?
classy_dog wrote:
How would you incorporate the code you listed above in the windows form
The first part goes into "Program.cs"; you can see the Main-method. The second part of the code goes in the form you're trying to show.
classy_dog wrote:
and then have the code return to the main method?
That would happen automatically; when an application is run, the Main-method is executed. The code as presented would display a form (modal), and continue execution on the line after the "ShowDialog" call, as soon as the form closes.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
classy_dog wrote:
How would you incorporate the code you listed above in the windows form
The first part goes into "Program.cs"; you can see the Main-method. The second part of the code goes in the form you're trying to show.
classy_dog wrote:
and then have the code return to the main method?
That would happen automatically; when an application is run, the Main-method is executed. The code as presented would display a form (modal), and continue execution on the line after the "ShowDialog" call, as soon as the form closes.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
There is one more thing to that. You would have to put
DialogResult.OK;
when you want to close Form, in order to
DialogResult.OK == f.ShowDialog()
be true. Best regards,
-
How would you incorporate the code you listed above in the windows form and then have the code return to the main method?