Thanks for both of your replies. I'd like to add a complete solution I found
for my problem in case someone needs it:
In form1 I have a static variable that I can access from form2 when form2 is
open.
In form1 I have an event that gets fired when form2 is closed. This is where
I handle whatever I want handled when form2 is closed. It looks like this:
// This is form1 code:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 f = new Form2();
f.Closed += new EventHandler(f_Closed);
f.ShowDialog();
}
private void f_Closed(object sender, EventArgs e)
{
_Act();
}
private void _Act()
{
MessageBox.Show ("Do whatever...");
}
hope this helps someone and thanks again to you two guys,
jay
"Michael C" <mi*******@optonline.net> wrote in message
news:2O********************@news4.srv.hcvlny.cv.ne t...
I had the same problem, and the way I got around it was passing a variable
into the Form2 constructor. You can also declare a static variable on
Form1 and set its value before calling Form2. I've asked around what the 'best'
or 'preferred' method is, but haven't received a response yet. But those
two options do work. The ShowDialog() method opens your form as a modal
dialog box, and returns a DialogResult you can use to determine which
dialog Button was pressed; or you can set its value manually in the modal dialog
if something went wrong.
Thanks,
Michael C.
"jay" <so***@nospam.com> wrote in message
news:cc**********@bagan.srce.hr...
I'm trying to open up an existing form from my main form. In that new
form, I want to pass a value to a starting form from a button click.
I'm using:
Form2 f = new Form2()
f.Show()
but how do I reference the Form1 from the Form2?
I tried using ParentForm property, but unsuccessfully.
I would also like to know how to open this new form (Form2) modally.
thank you,
jay