2011-05-12 64 views
3

嗨 我試圖以編程方式添加新的選項卡,我的控制,以Visual Studio 2010中問題在添加用戶控件工具箱編程

它創建標籤,但它不是添加控件標籤。

 //Getting design time environment 
     DTE DesignTimeEnvironment = (DTE)Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.DTE.10.0"), true); 
     //Getting tool box object 
     ToolBox VSToolBox = (ToolBox)DesignTimeEnvironment.Windows.Item("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").Object; 
     ToolBoxTab MyTab = null; 
     string TabName = "MyComponents"; 


    //checkin if Tab already exists 
    foreach (ToolBoxTab VSTab in VSToolBox.ToolBoxTabs) 
    { 
     if (VSTab.Name == TabName) 
     { 
      MyTab = VSTab; 
      break; 
     } 
    } 

    //If tab doesn't exist, creating new one 
    if (null == MyTab) 
     MyTab = VSToolBox.ToolBoxTabs.Add(TabName); 

    MyTab.Activate(); 
    ToolBoxItem tbi = MyTab.ToolBoxItems.Add("FileBrowser", 
    @"MyComponents.FileBrowser, MyTestComps, Version=1.0.0.1, Culture=neutral, PublicKeyToken=2283de3658476795", 
    vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent); 

    DesignTimeEnvironment.Quit(); 

如果我作爲管理員的工作正常運行,添加控件來控制庫, 但是當我嘗試添加這是不是在GAC它不工作的圖書館。它沒有任何例外。 例如:

ToolBoxItem tbi = MyTab.ToolBoxItems.Add("FileBrowser", 
    @"C:\MyComponents\MyTestComps.dll", 
    vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent); 

回答

相關問題