So I have Form1
and Form2
.
When I close Form2
using this.Close()
, I want Form1
to detect the close and execute a code.
Can this be done?
So I have Form1
and Form2
.
When I close Form2
using this.Close()
, I want Form1
to detect the close and execute a code.
Can this be done?
Yes you can execute whaever you want in FormClosing
event, but you need to
declare a static property on Form1
and set value on FormClosing
in Form2
, write whatever you want to execute in the set{}
method of peroperty.
// in Form 2
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
Form1.IsForm2Closed = true;
}
// in Form 1
private static _isForm2Closed ;
public static bool IsForm2Closed
{
get
{
return _isForm2Closed;
}
set
{
_isForm2Closed = value;
if(value)
{
// do whatever you want to execute here.
}
}
}