Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Drag a user control from the solution explorer to the designer window?
 

Drag a user control from the solution explorer to the designer window?

We have a large number of user controls/ custom controls in our solution. This causes an issue when we try to work in the designer.

Since we have the toolbox autopopulate=true the tool box gets rebuilt alot and it takes about 5-10 minutes to rebuild. 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. For example, drag/drop the user control file from the solution explorer.

Since we upgraded to VS 2008 we have to shutdown VS every hour because even selecting a control takes 10 seconds or so after editing in the designer for an hour.

I turned off autopopulate and plugins source control perform background status updates anddesigner editingseems to be normal.

The bottom line is that editing in the designer gets progressively worse to the point we can't work effectively without restarting VS and populating the tool box takes a long time.

Any help will be appreciated.
RiverSoft1996  Friday, August 14, 2009 1:29 PM
Here is an update:

I was unable to get the macro to work. All of our user controls are in the .exe so I did not try as you suggested to move the user controls to a DLL. Anyway, we found a workaround.

1) We set the autopopulate to false. We no longer have 5-10 minute delays while the toolbox autopopulates.
2) After we createnew user controls and need to add them to the toolbox we right-click on the toolbox and click on Choose Items...
3) From the Choose Items dialog we browse to the folder containing the .exe that contains the user controls and select the .exe.
4) Click Ok And that will add the new user controls.
5) Drag the new User Control(s) to the designer window.

Thanks for your help,

RiverSoft
  • Marked As Answer byRiverSoft1996 Tuesday, September 01, 2009 1:38 PM
  •  
RiverSoft1996  Tuesday, September 01, 2009 1:38 PM
Hi,

we are also having the same problem as you describe , our project is also contains many custom and user controls we also using visul studio 2008 . Taking a time to load the toolbox. The main problem we are facing to edit the control.
But one thing that i notice when you open the designer for edit just clike (CTRL + ALT + DEL) combination of keys and then press ESC key the designer window open properly but i didn't know the reason why it is happening in this fashion.

good luck.
Malik M.Shahid  Friday, August 14, 2009 8:22 PM
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.
Rong-Chun Zhang  Monday, August 17, 2009 9:33 AM

Hello,

Have you got any progress on this issue? If there is anything else we can help, welcome to post here.

If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Thanks,
Rong-Chun Zhang


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.
Rong-Chun Zhang  Wednesday, August 19, 2009 9:58 AM
Thanks Rong-Chun. This is basically what I was looking for. I will need to tweek the macro but I think this will work for us.

Again thanks
RiverSoft1996  Wednesday, August 19, 2009 2:38 PM
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90


Public Module VSEditor Sub AddItemsToMatItemToolbox() 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 = "C:\MySolution\MyProject\bin\Debug\mat.exe" Dim myTab As EnvDTE.ToolBoxTab For Each myTab In toolbox.ToolBoxTabs 'check if the specified tab is already existed If "My Items" = myTab.Name Then Exit For End If Next If myTab.Name = "My Items" 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 This works. The tab is added myTab = toolbox.ToolBoxTabs.Add("My Items") myTab.Activate() 'add the control item This does not work. The item is not added myTab.ToolBoxItems.Add("MyItem", ctrlDllPath,vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent) MsgBox("MyItem added!") End Sub

I modified the example code you gave (very little) and adding the Tab worked but adding the item did not work.

I set the ToolBoxItemAttribute for the class to:

namespace MyItem.UserControls
{
   [ToolboxItem(false)]
   public partial class MyItem : MyItembase // The base is a user control
   {
      public MyItem()
      {
         InitializeComponent();
      }
   }
}

I am using VS 2008 does that matter. I tried changing Dim myTab As EnvDTE.ToolBoxTab to Dim myTab As EnvDTE90.ToolBoxTab3 but that did not work.

I tried to changemyTab.ToolBoxItems.Add("MyItem", ctrlDllPath,vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent) to
myTab.ToolBoxItems.Add("MyItem.UserControls.MyItem", ctrlDllPath,vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent)

If you have any suggestions it would be appreciated.

RiverSoft1996  Wednesday, August 19, 2009 4:42 PM
Hello,

Based on my understanding, to add control to ToolBox, we need to put the user control into a DLL file. Therefore please try to put the control into a DLL file to see if it works for you.

More information
http://msdn.microsoft.com/en-us/library/envdte.toolboxitems.add.aspx

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.
Rong-Chun Zhang  Monday, August 24, 2009 4:02 AM
Hello,

Our project having a multiple Dataset with lot of Datatables , and User Controls these are displayed in toolbox is there any way on level to hide these stuff.

Thanks.
Malik M.Shahid  Monday, August 24, 2009 11:50 AM
Malik,

See Rong-Chun's first reply:

[ToolboxItem(false)]
public partial class TestUC : UserControl
{
}

This is the technique we use to "hide" a UserControl from the ToolBox autopopulate. My guess is that the ToolBoxItem(false) will work for the dataset/datatables as well.

If you don't want any userControl/dataset/datatables etc. to show in the toolbox then you can set the autopopulate to false from the options menu.

RiverSoft1996  Monday, August 24, 2009 1:04 PM

Hello,

I am writing to check the status of the issue on your side. Would you mind letting me know the result of the suggestions? If you have any additional question, welcome to post here.

Have a great day!

Thanks,
Rong-Chun Zhang


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.
Rong-Chun Zhang  Friday, August 28, 2009 12:22 PM
Here is an update:

I was unable to get the macro to work. All of our user controls are in the .exe so I did not try as you suggested to move the user controls to a DLL. Anyway, we found a workaround.

1) We set the autopopulate to false. We no longer have 5-10 minute delays while the toolbox autopopulates.
2) After we createnew user controls and need to add them to the toolbox we right-click on the toolbox and click on Choose Items...
3) From the Choose Items dialog we browse to the folder containing the .exe that contains the user controls and select the .exe.
4) Click Ok And that will add the new user controls.
5) Drag the new User Control(s) to the designer window.

Thanks for your help,

RiverSoft
  • Marked As Answer byRiverSoft1996 Tuesday, September 01, 2009 1:38 PM
  •  
RiverSoft1996  Tuesday, September 01, 2009 1:38 PM

You can use google to search for other answers

Custom Search

More Threads

• 3 layers.
• Prevent execution of a block of code at design time.
• Paste with default size?
• Adding buttons/tabs to a ToolStrip/TabControl in my custom user control all this in design-time
• ComponentsCreated & ComponentsCreating events not firing from IToolboxService Drag & Drop
• VS.NET Designer Host implementation location?
• adding items to a browse box
• How can I set focus in a web broswer on winform?
• MDI StartPostion.
• custom designer for smart device