Disable constructor for derived class in Visual Studio 2008

I have a class A derived from a Windows.Form class using the VS2008 constructor. When I double-click 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 functions, but the form is the same, but if I double-click on the name of my file in Visual Studio Solution Explorer, it will open the form designer. This is an undesirable behavior , especially since I will need to create similarly derived CZ classes.

Is there a way to make the file always open in the code editor? I know of two suggested workarounds:

  • Give class B the attribute: [System.ComponentModel.DesignerCategory ("")]

    This seems to have worked in the past according to various posts, but seems to have no effect in my situation. The VS environment is still trying to open the form designer for the class.

  • Rename the source file to valuefulname.Designer.cs

    This ... well, it's just not nice, is it?

Should solution (1) work? If so, what can I do wrong?

Or is there another solution?

+6
source share
1 answer

Try using [System.ComponentModel.DesignerCategory("Code")] instead.

+9
source

Source: https://habr.com/ru/post/901264/


All Articles