C # After closing the current form, the parent form is not initialized and displayed

Source: Internet
Author: User

Now we have a new requirement:

A winform, show a new form, and put your own hide. After the new form is closed, how can we show the parent form? [no more initialization of the parent form can be performed to keep the previous state displayed]

 

After checking the information, we found that there was a clever way to achieve it by entrusting it. It seems that you only have the entry level.

 

Public partial class form1: Form <br/>{< br/> Public form1 () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void button#click (Object sender, eventargs e) <br/>{< br/> This. hide (); <br/> form2 form2 = new form2 (); <br/> form2.show (); <br/> form2.closing + = form2_formclosing; <br/>}</P> <p> private void form2_formclosing (Object sender, formclosingeventargs e) <br/>{< br/> This. show (); <br/>}</P> <p> // note that form2_formclosing of Class B is in Class A </P> <p>/formclosing of Class B events are written in Class, in this way, B can be fully controlled in Class.

 

Some netizens also proposed another solution:

 

For example, to create a constructor with parameters, pass the instance of the first form to the previous one.

In form1

New form2 (this). Show ()
Or use a public function. [Well, I only heard about the method, and there is no specific implementation. Study later]

 

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.