问题
I have class A derived from a Windows.Form class, using the VS2008 designer. When I double click on the file name in Visual Studio Solution Explorer, the form designer opens. This is the desired behavior.
I have a second class B, derived from A (manually). This class is pure code - it adds some functionality but the form is the same - but if I double click on its file name in Visual Studio Solution Explorer, it opens the form designer. This is the undesired behavior, particularly as I will need to produce similarly derived classes C-Z.
Is there a way of forcing the file to always open in the code editor? I'm aware of two proposed workarounds:
Give class B the attribute: [System.ComponentModel.DesignerCategory("")]
This appears to have worked in the past according to various postings, but doesn't seem to have any effect in my situation. The VS environment still tries to open a form designer for the class.
Rename the source file to meaningfulname.Designer.cs
This... well, it just isn't nice, is it?
Should solution (1) still work? If so, what might I be doing wrong?
Or is there another solution?
回答1:
Try to use [System.ComponentModel.DesignerCategory("Code")]
instead.
来源:https://stackoverflow.com/questions/8088573/disable-designer-for-a-derived-class-in-visual-studio-2008