Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to tell Visual Studio not to treat a source file as a "component"? [duplicate]

Tags:

Possible Duplicate:
Is there an attribute I can add to a class so it will be edited as code, not in the designer?

Class with System.ComponentModel.Component on their inheritance path are automatically treated as "components" within Visual Studio (2008), triggering a different icon for the source file:

While the icon does not really matter, the changed double click behavior is really annoying: instead of opening the source code in the text editor, Visual Studio now shows a screen encouraging me to add components to my class by dragging them "from the Toolbox". I do not want to do that!

I am aware that I can right click the source file and choose "View Code", but whenever I forget to do this, I am stuck waiting for a dialog which is absolutely useless. Is there any way to disable the component behavior (preferably in the source code)?

like image 700
Jørn Schou-Rode Avatar asked Jan 26 '10 10:01

Jørn Schou-Rode


People also ask

What is source file in Visual Studio?

The Open source files in Visual Studio Code experiment allows you to use Microsoft Edge DevTools, but then edit your files in Visual Studio Code instead of in the code editor of the DevTools Sources tool.


2 Answers

Can't you use the DesignerCategory attribute to decorate your class ?

When decorating your class with this attribute like displayed below, the file should open in 'code view' when you double click it:

[System.ComponentModel.DesignerCategory("Code")] public class MyComponent { } 
like image 106
Frederik Gheysels Avatar answered Nov 06 '22 07:11

Frederik Gheysels


As OregonGhost already mentioned in his comment this also happens if you make a partial class file from a form.

The problem is even more worse. If you take a look into your project file you can find entries for every file include like this:

<Compile Include="FormMain.cs">   <SubType>Form</SubType> </Compile> 

So the solution should be to delete the line <SubType>...</SubType> cause it seems to be the root of all the problems. But if you delete this line, save the file, open it in Visual Studio, save it again and take a look again into, the line will reappear!

There seems to be only one hard-coded exception within Visual Studio and this is *.Designer.cs. So there is no solution to accomplish this problem.

like image 44
Oliver Avatar answered Nov 06 '22 07:11

Oliver