Define an global object from dialogForm in the button which open this dialog which exists in MainForm initialize new dialogForm object then get its string instance.
More...
DialogForm contains public string object which has the value of the texrbox
MainForm has global object from DialogForm
class MainForm : Form
{
DialogForm dialogForm;
On MainFormButtonClick
{
dialogForm = new DialogForm();
dialogForm.ShowDialog();
string whatWroteInDialogForm = dialogForm.stringValue;
dialogForm.Dispose();
}
}
Any miss understanding kindly reply..
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
>when I close the dialog, the instance of that Form2 form does not exists anymore
Not quite. Here's a common idiom that I see and use for dialogs:
MyDialog dlg = new MyDialog();
if ( dlg.ShowDialog() == DialogResult.OK ) {
// Filling a text box, for this example
this.textBox1.Text = dlg.ResultText;
}
ResultText would be a public property for the dialog:
internal class MyDialog: Form {
private string _resultText;
//...
public string ResultText {
get { return _resultText; }
private set { _resultText = value; }
}
//...
}
Another way to communicate between forms is events, but with dialog forms that's usually overkill.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>Please correct me if my understanding is not correct
It sounds good to me.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401