Visual Studio 2010: Add new class file that inherits from existing class? - c#

Is there a way in Visual Studio 2010 to add a new file (class) to a project that inherits from an existing base class, abstract or otherwise? This seems like a simple concept but I can't find a way to do it.
I'd like to be able to for example right click a class name in the IDE and and select "add new inheriting class" or something similar. Just one of those things that would save a lot of repetition. Ideally it would implement (generate stubs) for abstract members, etc.
Does anyone know a way to do this either through stock VS2010 or ReSharper? I've dug through both and can't find anything. Interestingly enough, Resharper will allow for generating a superclass, but not a subclass..

I don't think it's actually faster to right click -> add base class then to add a class file and type : Base behind it.
If you want to implement an abstract class you can right click on the base class and select "Implement Abstract Members"
You can also use the Class Diagram tool (right click a project and select View Class Diagram) then add a class and drag an inheritance arrow from the toolbox onto it.

If you are adding Form or User control, this option is available in VS2010, under Windows Forms Tab.

You could create a new item template for the base class(es) you find yourself using most often. Or you could extend Visual Studio and roll your own.

Related

VSIX extension to select class

I want to develop an extension for Visual Studio 2017 which will allow user to right click on C# class and choose to invoke wizard from the context menu. I see here that it is possible with VSIX template. I also looked into Roslyn and feels that it might be the way to go forward but not sure. Basically I wan to select the class and read all it's properties hierarchically to show it in tree view and let user decide select from those. The point I am stuck at is if it is possible in Roslyn and can I use C# reflection there as well.
Thanks
Jay

C# custom Windows Forms base class and designer

I am trying to implement the GUI part of a plug-in, which means that I have to inherit from a custom base class (which inherits from UserControl) included with the plugin assembly.
When implementing my own control, I would normally inherit from UserControl and going to the designer would be really straightforward (just double clicking on the solution explorer).
In order to be able to work with the designer, I do a first implementation using UserControl as base class.
The problem is that as soon as I change the base class into ApplicantTabControlPlugin (the custom base class provided by the plugin), I cannot open the designer for this control anymore. I.e., if I close the designer, it seems it is gone forever.
Is there any way to prevent this behaviour?
You should add
<SubType>Component</SubType>
to the project file entry of your base class.

List Box, c# Visual Studio 2010

One small question. I know the toolbox in Visual Studio has all the necessary components, but I was wondering if we could introduce our own "custom-made" tools. For example, the listbox tool. I've created a "SpeechListBox" class in which I've mentioned all the methods that I want my listbox to use, but when I'm in the "SpeechListBoxApplication" class (where I wanna use this listbox), the listbox with my methods doesn't show up, instead the general listbox tool that doesn't have my methods shows up.
What I want is to write something like private speechListBox1 SpeechListBox; and somehow introduce a visual form to the design class without confusing it with the toolbox's listbox. Making the program realize that I want this type of list box with all the extended methods, not the general toolbox type.
Is there any way to either make our own listbox or add methods to the original listbox tool?
Well, if you derive your SpeechListBox from a class that either is or derives from System.Windows.Forms.Control, when you compile your project it will show up in the Visual Studio control toolbox.
If you aren't sure which class to derive from, you'll have to make some decisions. If you want to hand-draw everything yourself, derive straight from Control itself. If you want to build a control is is a composite of other controls, consider deriving from UserControl. You don't explicitly list exactly what you're trying to do with your SpeechListBox, but you may want to consider just using a ListBox but supplying it with custom drawn list items. You could do this by making your class derive from ListBox or just configuring a ListBox to do what you want right in the form on which the listbox resides.
Is your code in separate project? Then you have to add that project to your SpeechListBoxApplication project's references in the solution explorer.
Otherwise your inherited control (public class SpeechListBox : ListBox) should show up, when in the GUI Designer in the toolbox in either the Common section or a section labeled after the project.

Extending UI Component Class in C#/VS2010

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?
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.
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.

Auto-generate an interface implementation in C#?

I know this is quite lazy but, is there any way on Visual C# 2010 Express to auto-generate an interface implementation? (I don't mean at runtime but at design time, like a code snippet). Perhaps with a third party utility?
I'm not familiar with Express enough to know if they removed this feature, but you should just be able to right-click your public class MyClass : MyInterface statement and choose "Implement Inteface".
If this is removed in Express, you can always use Resharper for this feature.
Right click on the interface name, you should see a menu option "Implement Interface" or along those lines.
With the cursor on the interface name, you can also press CTRL + . to get the same context menu and options.
In Microsoft Visual Basic 2010 Express, I just put the cursor to the end of the Implements line and press Enter - then the stubs are generated automatically
Public Class Class1
Implements IMyInterface1
move the cursor to the end of the word IMyInterface1 and press Enter

Categories

Resources