WinForm A continuous Click button to open a form only once

Source: Internet
Author: User

Many friends, when learning C #, the production of WinForm small program always has a problem, if we set in the parent form is clicked a button, open a subform, continuous click always appear continuously the same form, but we sometimes just want to open a form, how to do?

Hehe, I come to tell you, I hope to help you, of course, I understand the mood of beginners, can read, to ensure that the code is available, I hope to help you.

//set the public method to open only once Public Static intCXYPX (Form Frmmdifather,stringstrmdichild) {            intBreturn =-1;  for(inti =0; i < frmMdiFather.MdiChildren.Length; i++)            {                if(Frmmdifather.mdichildren[i]. Name = =strmdichild) {Frmmdifather.mdichildren[i].                    BringToFront (); Breturn=i;  Break; }            }            returnBreturn; }

//then add the following code to your button click event:Private voidAdd Billing Toolstripmenuitem_click (Objectsender, EventArgs e) {            intindex = CXYPX ( This,"ZD");//Remember, the ZD here is the name of the subform.            if(Index = =-1) {ZD tjzb=NewZD ();//Tjzb is an instance of a subform, and It's a place to change.Tjzb. MdiParent = This; Tjzb.            Show (); }            Else            {                 This. Mdichildren[index].            Show (); }        }

WinForm A continuous Click button to open a form only once

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.