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