I wonder if it is possible to create a form at run time. I do not want to instantiate an existing class
Please, help me :bigyello:
Printable View
I wonder if it is possible to create a form at run time. I do not want to instantiate an existing class
Please, help me :bigyello:
yes it's possible. You do it the same way you'd create a dynamic control with the New keyword. Then use AddHandler to hook up events, add dynamic controls and handlers for those too...
That's all there is to it.
Heck, if you look at the designer file you'll see that's exactly how it's done... all of the controls are created at run time, then added to the form. It's just that the IDE then takes that designer file and gives you a warm, soft GUI to work with. There's nothing to say that you can't hand-code it all yourself. But you're still instanciating a class (the form) ... so unless there's a fluid reason for doing so, there really isn't much point in it (other than an exercise in "gee this is far easier to do in the IDE").
-tg
The only time i've ever created my own forms that way was when creating an app that used the CodeDomProvider class to create executables...
You also don't need a designer file. Those were only introduced with the 2005 version when partial classes were added. Prior to that, all the designer code was just stuck into a region in the one and only code file for the form.