views:

46

answers:

4

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

A: 

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.

Oliver
A: 

You could right-click the source file, choose "View Code", then click "Set as Default". It's a bit of a blunt instrument, but if you have more false components in your solution than real components, then you may find it convenient.

Christian Hayter
+3  A: 

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
{
}
Frederik Gheysels
Thanks Frederik!
Christian Hayter
Exactly! It truly is weird that you *have* to use the fully qualified name for this attribute, though :)
Jørn Schou-Rode
A: 

See http://stackoverflow.com/questions/230146

Simon