Consider the situation where I have two windows forms, say F1
and F2
. After using F1
, I have now called F2.ShowDialog()
.
May be I am late. but all those who may want.
In destination form have a constructor defined like this
public partial class Destination: Form
{
string valueAccepted;
public Destination(string _valuePassed)
{
InitializeComponent();
this.valueAccepted= _valuePassed;
}
}
and in Source Form call the form like this
Source sourceForm= new Source ("value Passed");
sourceForm.ShowDialog();
this way "value Passed" is passed from Form Source to Form Destination
let me reframe the question i ve 2 form f1, f2... i cal Form f2 = new Form(); f2.ShowDialog();
// now i need to pass the parameter from f1 window to f2 (which is modal dialog box) also return value from f2 form to f1
//now 'm using varibles that are in common namespace (for both f1 , f2)
Add this code in the relevant place in your from f1.
Form f2 = new Form();
f2.ShowDialog();
HTH
Has anyone considered simply passing the value to the form in the tag attribute.
Form newForm = new form();
newForm.Tag = passValue;
newform.showmodal();
when newform is shown the load (or any other) routine can use the data in tag
public void load()
{
if (this.Tag.length > 0)
{
// do something with the data
}
}