.net - replace default form instance -


i using vb @ moment , vb has annoying feature called "default form instance", creates default instance of form object when reference form class instead of form instance.

ex:

public class frmmain     inherits system.windows.forms.form   end class    private sub sub1     frmmain.show()   end sub   

the code above compiles , runs without error because runtime gives new instance of frmmain when call class name.

the question is:

is there way replace default instance instance have created? way put it: there way set instance created default instance?

for ask "why on earth need ?":

i have application, let's call myapplication.exe, windows forms application , frmmain main form. many references in application main form through default instance, working fine until now. making changes application. instead of running myapplication.exe directly, have load assembly dynamically , run through reflection. here how it:

dim assembly reflection.assembly = loadassembly("myapplication.exe")   dim frm object = assembly.createinstance("myapplication.frmmain")   frm.show() 

i create , show instance of frmmain through reflection. later on, when application tries access frmmain through default instance, runtime creates new frmmain instance because thinks default instance not there yet. default instance , 1 on screen different objects.

bottom line is: through reflection trying mimic exact behavior of running myapplication.exe directly.

this cannot done evidenced trying set default instance form else

    dim newform new frmmain     my.forms.frmmain = newform 

this code throws argumentexception saying "property can set nothing"

you should add field , find , replace default form instance references explicit references

private _myfrmmain new frmmain private sub sub1 _myfrmmain.show() end sub 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -