Use reflection to manage the main form of a child program

Source: Internet
Author: User

Objective: To open a subroutine while the main program is running, and to hide and display the main form of the subroutine in a timely manner based on some logic in the main program.

The initial idea is to use the way to start the process, but to use the Win32 of some of the API, but also to find the form of what, in addition to the process of resource utilization will be more, so take the initiative to abandon the idea. Then thought of using reflection to complete the process.

        stringPath//Assembly Path        ObjectMyo; stringTypeform;//form type, which is Form1 or Form2         PublicChildmsg (stringPathass,stringtypeform) {             This. Path =Pathass;  This. Typeform =Typeform; }        //Initialize        Private BOOLInitit () {Try            {                if(Myo = =NULL) {Assembly Mainass=Assembly.LoadFrom (path); Myo=mainass.createinstance (Typeform); return true; }            }            Catch            {                return false; }            return false; }        //Open Method         Public voidOpenit () {if(Initit ()) {MethodInfo mi= Myo. GetType (). GetMethod ("Show",Newtype[] {}); Mi. Invoke (Myo,NULL); }        }        //Show and Hide         Public voidShow (BOOLYes) {PropertyInfo pi= Myo. GetType (). GetProperty ("Visible"); Pi. SetValue (Myo, yes,NULL); }        //Close         Public voidCloseit () {MethodInfo mi= Myo. GetType (). GetMethod ("Close",Newtype[] {}); Mi. Invoke (Myo,NULL); }

It feels like nothing new, a use example of reflection. This class package is not very good, I hope to make more valuable comments.

Use reflection to manage the main form of a child program

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.