Inherit from custom controls VS 2008
Is this possible? Must be surely but I've tried and come up short. I've created a very basic class (person) with 2 public properties, forename, surname. My user control is databound to this class and has 2 textboxes to store the properties.
I've built the control and can add the user control to a windows form but how can I add to a new user control (Staff) which will show my 2 existing textboxes and I can add dateJoined datepicker also??
Cheers for any help.
Re: Inherit from custom controls VS 2008
A class inheriting from another control should not be a UserControl (as that's a class inheriting from UserControl). Instead, you just create a new (blank) class, and manually have it inherit from the control you want.
For example, if you wish to create a control that inherits from Button, you create a new blank class and type this:
Code:
Public Class MyButton
Inherits Button
End Class
If you do want a UserControl (meaning, you want to add some other controls to your existing layout, like adding a Button to a Treeview or something), then you create a blank UserControl and simply drop an instance of your other UserControl on this new UserControl.
Re: Inherit from custom controls VS 2008
Hi Nick
Thanks for the response mate. I am unable to "drop" an instance of my UserControl1 onto my UserControl2. I don't see it in the toolbox. When I try to add the dll to toolbox I am informed there are no controls that can be added. Have I done something wrong?
Cheers.
Re: Inherit from custom controls VS 2008
You didn't mention a DLL before.
Anyway, if you have two UserControls in the same project (or same solution of one project references the other), then you should be able to add an instance of one UserControl to the other.
Did you build the solution first? As you seem to know judging from your first post you need to build the solution before any controls show up in the Toolbox.
You are looking at the design surface of the UserControl, right?
Re: Inherit from custom controls VS 2008
Hiya Nick
I have built the UserControl1 control which has my two textboxes then I start a new project of type control library. I add reference to my UserControl1 library but see no UserControl1 in the toolbow in design view.
As I couldnt see the control I tried to add to the toolbox by pointing directly to the UserControl1 dll but not able.
Re: Inherit from custom controls VS 2008
How are you adding a reference? You should be adding a Project reference (via the Projects tab in the add reference window). Then, you should still build your solution, and then it should appear in the toolbox.
Re: Inherit from custom controls VS 2008
I'm adding a reference to the project but still don't see my user control in the toolbox.