Hello,
Thanks for your posting on MSND forum.
>I was wondering if their is a way to manually add one user control/custom control to the designer not using the toolbox to drag/drop from.
My suggestion is that we can hide the control from being shown in the ToolBox by setting the
ToolboxItemAttribute .
[ToolboxItem(false)]
public partial class TestUC : UserControl
{
}
Then we can add the control to ToolBox by using the following Macro.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module DesignerToolBox
Sub AddItems()
Dim window As EnvDTE.Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox)
'get the ToolBox instance
Dim toolbox As EnvDTE.ToolBox = window.Object
'specify the path to the control component
Dim ctrlDllPath As String = "E:\Control_Components\Mycontrols.dll"
Dim myTab As EnvDTE.ToolBoxTab
For Each myTab In toolbox.ToolBoxTabs
'check if the specified tab is already existed
If "My Tab" = myTab.Name Then
Exit For
End If
Next
If myTab.Name = "My Tab" Then
'if the the specified tab is already existed,
'delete it so all child items are deleted too
myTab.Activate()
myTab.Delete()
End If
'add new tab
myTab = toolbox.ToolBoxTabs.Add("My Tab")
myTab.Activate()
'add the control item
myTab.ToolBoxItems.Add("TestUC", ctrlDllPath, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent) MsgBox("Control added!")
End Sub
End Module
Information about Macro
http://msdn.microsoft.com/en-us/library/b4c73967.aspx More information, please check my thread on VSX(Visual Studio Extensibility) forum, if you have any question about VSX, you can post on that forum.
http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/d9ffc563-1e23-445e-9254-046d7af02d5f/ Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact
msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.