Avatar of rvin2
rvin2

asked on 

How to load (at runtime) a Winform UserControl?

Hi Experts,

How to load (at runtime) a Winform UserControl?
.NET Programming

Avatar of undefined
Last Comment
psasik
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Create an instance and add it to some container...

    UserControl1 uc = new UserControl1();
    // set some props on "uc"...
    uc.Location = new Point(25, 50);
    this.Panel1.Controls.Add(uc);
Avatar of psasik
psasik

Idle's answer is great. i would just add that Forms are containers too. There's no need for a Panel, GroupBox etc.

This will work just fine:

this.Controls.Add(uc);

Cheers.
Avatar of rvin2
rvin2

ASKER

Sorry for the confusion.
I'm trying to load a specifc UC from a DLL (collection of UC).
Thanks!
Avatar of psasik
psasik

OK. You'll need to use .Net reflection.

Start here: http://msdn.microsoft.com/en-us/library/5713xtes.aspx

Load the module/dll

Find the class to instantiate

Use code above to add the instance to a form
Avatar of psasik
psasik

Here's a better example actually that includes code for instantiating the class:

http://msdn.microsoft.com/en-us/library/system.reflection.assembly(VS.80).aspx
ASKER CERTIFIED SOLUTION
Avatar of psasik
psasik

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo