views:

61

answers:

2

I've only just started using C#/VS this past week and wondered how to do something which, I think, should be quite simple:

What I want to do is extend the class used by a UI component and therefore implement my own methods in it - just for one instance of a UI component though. If I was using xcode/objective c I would normally just change the class name of the component in interface builder and it would become an instance of that class which would in turn extend the original UI class.

How do I do something comparable using C#/Visual Studio?

A: 

Remember that all (or most) UI components are classes, so they can be "extended" just like any other class.

Some will have virtual members you can override to take special actions. In all cases, you can add properties, methods, and events to the components.

Once you've created and built them, you can use them from the Toolbox, just as though they were the "built-in" .NET components.

John Saunders
+1  A: 

You can take any component class in Windows Forms and subclass it. Visual controls all derive from the Control class and you can do so as well.

If your component is a User Control (i.e., it derives from System.Windows.Forms.UserControl), it should automatically appear in the Toolbox after you build the project. For other components, you can add them to the Toolbox by right-clicking on the Toolbox and select Customize Toolbox, selecting the .NET Framework Components tab, clicking the Browse button, and selecting the DLL with the control.

Mark Cidade
I understand that. How, though, could I then apply this extended TextBox class to a TextBox in design view? IE - without instantiating and positioning it through code, or is that the only way?
JoeR
I updated my answer.
Mark Cidade
Excellent, thanks for your help!
JoeR