I am a begining C# programmer using Visual Studio 2005 Beta and have the following question.
How can I access values from common controls, like a ComboBox, or variables within Form1 (the parent) from Form2 (a dialog) and vice versa?
Scenario:
In Form 1 the User enters form data.
In Form 2 the input data is processed and the results are displayed in a new form
with readonly textboxes.
An explanation plus a code snipplet would be apreciated.
Loading
NschanPosted Oct 1, 2005, 5:47 PM
Below is a simple example of a parent form that opens up a secondary results dialog:
class ParentForm
{
...
private void showResults_Click(object sender, EventArgs e)
{
// 1. Create an instance of the results dialog.
ResultsForm dlg = new ResultsForm();
// 2. Copy necessary input data TO the results dialog.
dlg.InputValue = Int32.Parse(this.inputValueTextBox.Text);
// 3. Show the results dialog.
if ( dlg.ShowDialog() == DialogResult.OK )
{
// 4. Optionally copy back any modified values FROM the results dialog.
this.outputValueTextBox.Text = dlg.OutputValue.ToString();
}
}
}