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 / Visual Studio.NET / Extensibility / November 2004

Tip: Looking for answers? Try searching our database.

Adding Control to Form from different assembly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Trevor Germain - 09 Nov 2004 19:22 GMT
I have a control packaged in an assembly that has many other dependencies. I
want to programmatically add the control to a form at Design time.

When I drag my control from the toolbox manually, Visual Studio
automatically adds all of my control's dependent assemblies to the
application's references list.

When I use DesignerHost.CreateComponent, and set the created component's
parent property to my form, I can get the control to be added, but the
necessary references aren't added. So, naturally, when I try to build, or
close and re-open the form, my project has no idea how to re-create the
control.

How do I add the dependent assembly references to my project before adding
my control instance to the form (programatically). Or is there a better way
to have the control added to the form for me (maybe using IToolBoxService or
something?)

Trevor Germain
Trevor Germain - 10 Nov 2004 18:48 GMT
I may not have been able to accurately describe my problem in my original
post, but I have managed to come up with the solution on my own.

FYI:
Here is how to reproduce the "Double Click" behavior of an item in the
toolbox, to allow VS to add the control to the form, including adding any
necessary references to the project, and correctly initializing all designer
components.

IDesignerHost _DesignerHost =
(IDesignerHost)GetService(typeof(IDesignerHost));
using (DesignerTransaction transaction =
_DesignerHost.CreateTransaction("Add Component"))
{
   DocumentDesigner designer =
_DesignerHost.GetDesigner(_DesignerHost.RootComponent) as DocumentDesigner;
   if (designer != null)
   {
       IToolboxUser toolbox = designer as IToolboxUser;
       if (toolbox != null)
           toolbox.ToolPicked(new ToolboxItem(typeof(    <whatever
component / control you wish to create>    )));
   }
   transaction.Commit();
}

Trevor
>I have a control packaged in an assembly that has many other dependencies.
>I want to programmatically add the control to a form at Design time.
[quoted text clipped - 15 lines]
>
> Trevor Germain

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.