Overriding Designer attribute in derived class - c#

I have a class that inherits the built in System.Windows.Forms.Panel class. According to the metadata of the Panel class, it has an attribute named Designer. I am assuming this is what is causing my derived class to open in the form designer by default, rather than the code view. Is there a way I can override this attribute so that the file opens in code view?

I've found the answer. Thanks goes to Visual Studio: Make view code default using attribute.
[System.ComponentModel.DesignerCategory("")]

You could simply right-click and select "View Code" in VS, either in the Solution Explorer or in the designer view.

Related

C# Find Places an Abstract Class is used

I had an abstract class Foo. I want to get a list of classes that derive from it. All my searches are returning how to do it via code, and really I'm just wondering if there's some built in feature of VS that will do it for me... seems simple enough just to get a list for non-programming purposes. Thanks
In VS2012 Solution Explorer expand the file icon, right click the abstract class and click Derived Types.
Alternatively open the class in Class View, right click and Show Derived Classes.
Go to the abstract class, right click on the class name and select option "Find All References".
Right click on the name of your class and choose Find all references.

Visual Studio -- Expanded Intellisense View (Like a mapped treeview)

When you are typing with Intellisense and it shows you the parameters within a class, you can select a parameter and keep going until you arrive at the base level. When you are debugging, Visual Studio lets you stop on objects and inspect all of the parameters or fields within them.
Is there a way to build a treeview or diagram of all of the class parameters? I have a large class that included ton of sub objects and properties and I would like to build a view of all of its properties.
If you are just talking about being able to visualize your classes (through Visual Studio, not actually building a hierarchy through code) you can do it like this: In Visual Studio, click View - Class View. This will give you a tree view of your classes.
If you click View - Object Browser you will see a tree view of classes in other assemblies too, not just your classes.
EDIT
I think you are looking for something like the Solution Navigator in the Productivity Power Tools Visual Studio extension. Click Tools - Extension Manager - Online Gallery. Search for Productivity Power Tools and install it. You will then see an option under the View menu for the Solution Navigator.
If you want control over the way variable values are displayed during Visual Studio debugging sessions, you can apply the DebuggerDisplay attribute to the class of interest. You can alternatively overload ToString() on the class of interest to print the info you desire, assuming that this behavior would not conflict with any other requirements you may have.

Is it possible to configure the Class Diagram view to generate auto-implemented properties, rather than non-implemented ones? [duplicate]

I'm using the class designer in Visual Studio 2008 and when I add properties to my classes they are created with an empty setter and a getter that throws a NotImplementedException. In the properties window there's an option called "Auto-Implemented" which is always greye out. Is there a way to change the settings for this so by default new properties will be auto-implemented or some way to turn this option on so I don't have to keep editing the code each time I add in a new property?
AFAIK, you can't. I asked this at Barcelona a year or so ago - I don't think anything has changed. Basically, as I understand it, this is done directly (not via an editable snippet).
For visual studio 2008
you could install this "power toys" that give you another option to class designer menu
"create auto-implemented property"
http://modeling.codeplex.com/
i'll waiting this for Visual Studio 2010 too... else it's so annoying
You can create field, and encapsulate it(Refactor->Encapsulate field).
This can help for simple properties.
You can also create a property by using snippet propfull, then Tab, Tab.

How do I fix these C# errors?

I found some code to help me in a project and when I first ran the code I received an error message indicating: "Visual Studio cannot start debugging because the debug target c:\path\'dirInfo.exe' is missing. Please build the project and retry, or set the OutPath and AssemblyName properties appropriately to point at the correct location for the target assembly."
Then I select OK and receive an error message indicating that partial is missing. I add partial to the code and receive 3 more error messages.
The type 'RecursiveSearchCS.Form1' already contains a definition for 'components'
does this mean I should delete this from the Form1.cs file?
Type 'RecursiveSearchCS.Form1' already defines a member called 'Dispose' with the same parameter types.
Type 'RecursiveSearchCS.Form1' already defines a member called 'InitializeComponent' with the same parameter types.
(I notice, when I comment out the InitializeComponent line and/or Dispose line, many more error messages populate in ERRORS)
By they way you can find the original code # MicrosoftSite.
Any help would be greatly appreciated.
Thank You
Just gut instinct, if you were following along and copy pasting remember one key thing:
The designer creates two files when you create a form: A "code" file, and a "designer" file. However, when microsoft (and others) release "templates", they like to merge these two files.
Just create a new .cs file and paste the code and all should be good. It's the code basically saying "in the designer, we already have this stuff". (a good way to note this is the "partial" keyword located before your Form1 declaration)
More info:
The Code file will house all your own implementations. That is click events, methods you personally override, events you bind to, etc. This is the default file when you select "View Code" from either your solution explorer or the dialog itself. Within this file is a construct that calls a "hidden" method, (InitializeComponent) that if you right click and "Go to Definition" will bring you to the next file:
The Designer file is the IDE's generated file. This takes everything you do in the designer and stores it for you. That includes new controls, location and properties of the controls, and the IDisposable implementation. The idea is to keep the "meat an potatoes" out of the way while you worry only about implementation.
Yes it sounds like you've copied the entire code which includes many things already contained within your Form in a partial class. Either remove these or remove the partial class and partial class declaration from your Form to get rid of these errors
I went to the Microsoft site to see what you did. The site shows code for an entire "one file" solution. We've all agreed that Visual Studio creates multi-file solutions, so you're duplicating code.
I don't know if the current answers/comments have helped you get this sample code working, so I thought I'd add my share. I was able to get this sample working by doing the following:
First, where the sample code at the Microsoft site shows declarations for button, textbox, labels, and combobox, rather than attempting to copy that portion, I simply used the toolbox and dragged a button, the labels, the textbox, and the combobox from the toolbox to my form.
You'll probably want to arrange these to your liking.
This process created my form correctly with the appropriate objects on it. All I had to do was use the properties window for each object and rename them according to what they were named in the sample. For example, my new button was originally button1, but I renamed it to btnSearch just as it is named in the Microsoft sample.
I noticed that the Microsoft sample has an established event handler setup for the Form1_load() event. I created this same event in my form by clicking the form in the designer, clicking properties, clicking on the Events button in that properties, and double-clicking the "Load" event. This automatically generated the appropriate code.
In a similar way, I had to create the btnSearch_Click() event. I did this by simply double-clicking the button in the designer.
After that, all I had to do was manually copy and paste from the specific sections of the sample to my code -- fill in the Form1_Load() event with what was in the sample. Copy the DirSearch() method over. Fill in the btnSearch_Click() event. That was it.
I hope this helps solve the overall issue and gives you more insight into how you can avoid these problems in the future.
You have duplicated functionality in the classes, you have a file that was automatically generated with that functionality already in it.

Expand the List of Class Members in VS 2008

Is there any add-in for VS2008 Pro that provides me the ability to expand and see the list of members of each class - methods, properties,etc... - by expanding its tree node in Solution Explorer?
not possible from solution explorer, but is available via the Class View. go to the View menu and click on Class View to open it up.
Object Browser?
http://msdn.microsoft.com/en-us/library/exy1facf%28VS.80%29.aspx
In Solution Explorer you can click either on the project or individual file and select 'View Class Diagram'. It creates a diagram for all your classes. To see members of the class click on the down arrow next to the class name.

Categories

Resources