How do I close the parent form? C # (resolved)

Source: Internet
Author: User

I am used to the flexibility and simplicity of VB6. There are still some inhabits in C. In C #, I created two forms: Form1 and Form2. I added a Button1 in Form1 and added the following code:

Form2 newForm = new Form2 ();

NewForm. Show ();

Then, I added two buttons in Form2. Button1 and Button2. I added the following code in the Click event of Button1:

This. Close ();

The purpose is to disable Form2.

I added the following code in the Click event of Button2:

This. ParentForm. Close ();

My intention is to close its parent form, that is, Form1. However, the following error occurs when this statement is executed:


Why? How can I close the parent form? I hope that you will be able to learn from others.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.