Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2004

Tip: Looking for answers? Try searching our database.

Dynamically Add User Controls to a Form at Run Time?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stewart Armbrecht - 29 Feb 2004 16:49 GMT
Is it possible to dynamically load a user control on a windows form similar
to the way you can load a web user control to an aspx page.  Basically, I
would like the database to determine which controls are loaded to a form.  I
am trying to mimic the IBuySpy portal functionality in a windows
application.  Any ideas on how to do this?
Stewart Armbrecht - 29 Feb 2004 19:43 GMT
I found this:

You use System Reflection to dynamically load a control. If the DLL is named
"SpecControls.DLL" and the class you want is "SpecControls.ColorControl",
then use this code.

[C#]

    // load the assembly
    System.Reflection.Assembly assembly =
Assembly.LoadFrom("SpecControls.DLL");

    // get the type
    Type t = assembly.GetType("MyControls.MyControl");

    // create an instance and add it.
    //
    Control c = (Control)Activator.CreateInstance(t);
    parent.Controls.Add(c);

[VB.NET]

     ' load the assembly
    Dim assembly1 As System.Reflection.Assembly =
Assembly.LoadFrom("SpecControls.DLL")

    ' get the type
    Dim t As Type = assembly1.GetType("MyControls.MyControl")

    ' create an instance and add it.
    '
    Dim c As Control = CType(Activator.CreateInstance(t), Control)
    parent.Controls.Add(c)

If you have any better ideas let me know!

> Is it possible to dynamically load a user control on a windows form similar
> to the way you can load a web user control to an aspx page.  Basically, I
> would like the database to determine which controls are loaded to a form.  I
> am trying to mimic the IBuySpy portal functionality in a windows
> application.  Any ideas on how to do this?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.