Why has Visual Studio marked my class as a component?
I have copy pasted some classes into this project, some from other projects. At some point VS has marked Class1
as a component (you can see from the icon shown in the screenshot above). Class2
is OK. There's no difference in the File Properties and no interesting difference in the code between Class1
and Class2
(*except see edit below)
It doesn't stop the code from compiling or running. Is it in fact a problem at all? It is inconvenient in that the IDE tries to open the Design window if you double click the file.
How does this happen, and how to fix?
Edit: Actually, there are interesting differences in the code window. At least, there must be, sin开发者_开发知识库ce removing a large chunk of the code causes the Solution Explorer to revert the file to a Class file. Restore the chunk and the file goes back to being a Component. Currently... investigating.
I'm not sure why it does this thing, but I know how to get rid of it. Before your class put:
[System.ComponentModel.DesignerCategory("Code")]
It should work.
For the "why" part of your question (taken from this post which appears to be a duplicate):
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:
精彩评论