Make your variable as static
public static ShopMaster shopmaster=null;
then write the code in FormClosing event of your ShopMaster
private void ShopMaster_FormClosing(object sender, FormClosingEventArgs e)
{
string ans = (MessageBox.Show("Are you sure to Exit!", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)).ToString();
if (ans == "Yes")
{
Home.shopmaster=null;
}
else
{
e.Cancel = true;
}
}