Learn more about C # Implementing method Sharing for closing child windows without releasing child window objects

Source: Internet
Author: User
Here is a small series for everyone to bring a C # implementation to close the child window without releasing the child Window object method. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

In the debugging process of the online scanning camera, it is necessary to develop a debugging interface to configure the location. After debugging, a common way is to save the debug parameters and load the next time you start. Another simple way is to run the program directly using this parameter. Therefore, in the latter case, the function that needs to be implemented is that the Window object is not freed even if the debug window is closed. The object of its debug window is destroyed unless its main window is closed.

1 instantiating a child window in the main window

Instantiates a child window in the main window instead of instantiating the child window object in the button.

Form2 F2 = new Form2 ();

2 displaying the main window via a button

What you need to implement in the button is the display of the window

private void Config_click (object sender, EventArgs e)    {      F2. Show ();    }

3 Ways to close child windows without releasing child window objects

It is possible to modify the Dispose method in the Subwindow by querying and empirically. The changes are as follows:

protected override void Dispose (bool disposing)    {      Hide ();      if (disposing && (components = null))      //{      //Components  . Dispose ();      }      //base. Dispose (disposing);    }

4 Destroying a child window object when the parent window is closed

Because the child window object needs to be destroyed when the parent window is closed, the destroy function that calls the child window F2 is added in the close action formclosed of the parent window.

private void Form1_formclosed (object sender, Formclosedeventargs e)    {      F2. Close ();    }

The closing function added in the child window class is as follows:

public void Close ()    {this      . Dispose ();    }
Related Article

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.