Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to close form when i call the private function in windows form. How can i do it what i have tried is .my function not working when i tried it. Need Help

What I have tried:

frmDBVerify frmclose;

       private void Test() {

           this.frmclose.Close();
       }
Posted
Updated 29-Oct-20 20:07pm
v2

1 solution

for your code to work, 'frmclose needs to have a valid reference to the instance of 'frmDBVerify you wish to close:
private frmDBVerify frmclose;

private void Form1_Load(object sender, EventArgs e)
{
    frmclose = new FrmDBVerify();
    frmclose.Show();
}

private void Test() {

    if (frmclose == null) throw new NullReferenceException();

    this.frmclose.Close();
}
Note that calling 'Close on an instance of a Form that has been created using 'new, but not 'Shown, will not throw an error.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900