|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hide custom control in VS.NET toolboxI have created a set of custom controls, which all inherit from one base
control. I am using these controls within the same project, so they I would like to hide the base control so that it does not show up in "My User Controls". Is there a class attribute I can set to accomplish this? You can try the ToolboxItemAttribute.
http://groups.google.ca/group/microsoft.public.dotnet.framework.windowsforms.controls/msg/208f561150309157?hl=en http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodeltoolboxitemattributeclasstopic.asp Alternatively, if the base class should never be instantiated then you may consider making it "abstract" and it shouldn't show up in the Toolbox. -- Show quoteHide quoteTim Wilson ..NET Compact Framework MVP "David McClelland" <DavidMcClell***@discussions.microsoft.com> wrote in message news:DAE98473-EBAF-48D9-BCF5-D5E79DF1F954@microsoft.com... > I have created a set of custom controls, which all inherit from one base > control. I am using these controls within the same project, so they I would > like to hide the base control so that it does not show up in "My User > Controls". Is there a class attribute I can set to accomplish this? Hello Tim,
Thanks for the suggestions. I am using Visual Studio .NET 2003, and my controls (base and derived controls) are in an assembly called MI.UI.dll. I have tried the following with my base control: <System.ComponentModel.ToolboxItem(False)> _ Public Class MICompositeControlBase Inherits System.Windows.Forms.UserControl .... However, this base control still shows up in the Toolbox (when I reference the MI.UI project directly) along with the other controls, or NOTHING shows up in the Toolbox (when I reference the compiled MI.UI.dll assembly). This appears to be a problem for other people, as described here: http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.buildingcontrols/browse_frm/thread/89923daf965d9b71/c03a3a4b042d9a0e?q=toolboxitem&_done=%2Fgroups%3Fq%3Dtoolboxitem and here: http://www.lemanix.com/nick/archive/2005/02/08/1656.aspx I have also tried making the base class abstract (MustInherit in VB.NET), but this does not hide the base control from the Toolbox either. In addition, this has the unfortunate sideeffect that I cannot any longer open the designer for the derived controls, because of this message: An error occurred while loading the document. Fix the error, and then try loading the document again. The error message follows: The designer must create an instance of type 'MI.UI.MICompositeControlBase' but it cannot because the type is declared as abstract. - David McClelland Show quoteHide quote "Tim Wilson" wrote: > You can try the ToolboxItemAttribute. > http://groups.google.ca/group/microsoft.public.dotnet.framework.windowsforms.controls/msg/208f561150309157?hl=en > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodeltoolboxitemattributeclasstopic.asp > > Alternatively, if the base class should never be instantiated then you may > consider making it "abstract" and it shouldn't show up in the Toolbox. > > -- > Tim Wilson > ..NET Compact Framework MVP > > "David McClelland" <DavidMcClell***@discussions.microsoft.com> wrote in > message news:DAE98473-EBAF-48D9-BCF5-D5E79DF1F954@microsoft.com... > > I have created a set of custom controls, which all inherit from one base > > control. I am using these controls within the same project, so they I > would > > like to hide the base control so that it does not show up in "My User > > Controls". Is there a class attribute I can set to accomplish this? > > > The best thing to do would be to make the base control MustInherit since it
doesn't sound like you want to be able to make instances of this control. However, you would not be able to visually design the derived controls since the designer needs to create an instance of the base class and it cannot since it is "MustInherit", as was indicated by the error message. So you'll need to either not visually design the controls or you'll need to use the ToolboxItemAttribute. It looks like that ToolboxItemAttribute is getting inherited on the derived controls. What you can do is indicate that the base control should not show in the Toolbox and then indicate on derived controls that they should. Then when you compile the control assembly and add it to the Toolbox only the derived controls will show. <System.ComponentModel.ToolboxItem(False)> _ Public Class BaseControl Inherits System.Windows.Forms.UserControl ... End Class <System.ComponentModel.ToolboxItem(True)> _ Public Class DerivedControl Inherits BaseControl ... End Class -- Show quoteHide quoteTim Wilson ..NET Compact Framework MVP "David McClelland" <DavidMcClell***@discussions.microsoft.com> wrote in http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.buildingcontrols/browse_frm/thread/89923daf965d9b71/c03a3a4b042d9a0e?q=toolboxitmessage news:F35B0DA4-1086-47EB-AA56-7F402B2E0D9B@microsoft.com... > Hello Tim, > > Thanks for the suggestions. I am using Visual Studio .NET 2003, and my > controls (base and derived controls) are in an assembly called MI.UI.dll. I > have tried the following with my base control: > > <System.ComponentModel.ToolboxItem(False)> _ > Public Class MICompositeControlBase > Inherits System.Windows.Forms.UserControl > ... > > However, this base control still shows up in the Toolbox (when I reference > the MI.UI project directly) along with the other controls, or NOTHING shows > up in the Toolbox (when I reference the compiled MI.UI.dll assembly). This > appears to be a problem for other people, as described here: > > em&_done=%2Fgroups%3Fq%3Dtoolboxitem Show quoteHide quote > http://groups.google.ca/group/microsoft.public.dotnet.framework.windowsforms.controls/msg/208f561150309157?hl=en> and here: > > http://www.lemanix.com/nick/archive/2005/02/08/1656.aspx > > I have also tried making the base class abstract (MustInherit in VB.NET), > but this does not hide the base control from the Toolbox either. In > addition, this has the unfortunate sideeffect that I cannot any longer open > the designer for the derived controls, because of this message: > > An error occurred while loading the document. Fix the error, and then try > loading the document again. The error message follows: The designer must > create an instance of type 'MI.UI.MICompositeControlBase' but it cannot > because the type is declared as abstract. > > - David McClelland > > > > "Tim Wilson" wrote: > > > You can try the ToolboxItemAttribute. > > > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodeltoolboxitemattributeclasstopic.aspShow quoteHide quote > > > > Alternatively, if the base class should never be instantiated then you may > > consider making it "abstract" and it shouldn't show up in the Toolbox. > > > > -- > > Tim Wilson > > ..NET Compact Framework MVP > > > > "David McClelland" <DavidMcClell***@discussions.microsoft.com> wrote in > > message news:DAE98473-EBAF-48D9-BCF5-D5E79DF1F954@microsoft.com... > > > I have created a set of custom controls, which all inherit from one base > > > control. I am using these controls within the same project, so they I > > would > > > like to hide the base control so that it does not show up in "My User > > > Controls". Is there a class attribute I can set to accomplish this? > > > > > >
Other interesting topics
Browse for folders dialog
binding to an empty IBindingListView instance fails ClickOnce via Response.Redirect Creating a modal process Check if a form or control is visible in Desktop (to the user) Where to Put DAL and Business Objects in WinForms App? Winform rants... What aspx Stands for? Smart Navigation is not working compact framework combo box |
|||||||||||||||||||||||