Solution for not closing the process when you click Close in Form

Source: Internet
Author: User

I believe that many of my friends will always encounter various problems in daily programming. The solution to clicking the close button on the form does not close the process is that many friends think it is very difficult to learn.. net, the following is a brief introduction by Dana.

This problem is also caused by insufficient experience in developing the form project.

When developing a small tool, because there are multiple form forms, the redirection between multiple forms is as follows:Code:

Private void button#click (Object sender, eventargs e) {This. hide (); urllist form = new urllist (this. cbuserid. selecteditem. tostring (); form. show ();}

In this way, I click the close button on the urllist form. If I want to debug it again, I will report that the file "OBJ \ debug \ autopage.exe" cannot be copied to "bin \ debug \ autopage.exe ". The file "bin \ debug \ autopage.exe" is being used by another process. Therefore, this process cannot access this file. It is very troublesome to disable the process in the task manager before debugging. I guess it is because the above this. Hide () only hides the current window and does not close it. So when I close another window, this window is still not closed.

Solution: Close all application windows in the form formclosed event. The Code is as follows:

Protected virtual void main_formclosed (Object sender, formclosedeventargs e) {application. Exit ();}

Extended: when developing a project, whether it is a web project or a form project, it is best that all forms inherit the base class, so that many common functions can be implemented in the base class. For example, if the above Code has a base class, you don't need to process the formclosed event of each form. You just need to process the base class!

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: 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.