Problem solve Get help with specific problems with your technologies, process and projects.

Loading controls at runtime in VB.NET

How can I load controls at runtime in VB.NET as we used to use 'Load' keyword to load any control?
While it's relatively simple to New up a control and plop it on the form, there's the whole big problem of how to handle those dynamically created controls events. If you can't handle the button click, there's no sense in putting the dynamically created button on the form in the first place.

Instead of writing a whole article on answering this question, I'll refer you to Marc Clifton's excellent two-part article that shows a solid architecture on handling dynamic controls in building a system to allow you to reuse the same UI for both Windows Forms and Web Forms!

  • http://www.thecodeproject.com/cs/miscctrl/dynamicforms.asp
  • http://www.thecodeproject.com/cs/miscctrl/dynformpartii.asp
  • Dig Deeper on Win Development Resources

    Start the conversation

    Send me notifications when other members comment.

    Please create a username to comment.