2

Let's look at two pieces of code:

enter image description here

and:

enter image description here

For some reason, VS 2017 sees them differently:

enter image description here

And when I try to open the second file:

enter image description here

Sure, I can right click on the file and click on "View Code" but this behavior is weird.

Is it intended, or is it a bug?

Thomas
  • 10,933
  • 14
  • 65
  • 136
  • 2
    That is because of the base class of WebClient, System.ComponentModel.Component. Components have a design surface and the default click action is to show that surface. By design, but sure, not exactly very useful. That WebClient derives from Component is also a strange design decision whose reasoning is lost in the fog of time. If they could do it all over again then it probably wouldn't, but what happened in version 1.0 can't be undone. – Hans Passant Jun 22 '17 at 18:22
  • nice info, thanks! – Thomas Jun 22 '17 at 19:49
  • I wasn't having this problem with VS2017 - until I installed the optional library to allow me to create "Setup projects". Now, each .cs file pointlessly opens in Design Mode. Nice testing, Microsoft... – Mike Gledhill Aug 24 '17 at 13:00
  • Does this answer your question? [Visual Studio opens my class-file (.cs) in the designer mode](https://stackoverflow.com/questions/11880589/visual-studio-opens-my-class-file-cs-in-the-designer-mode) – StayOnTarget Nov 03 '21 at 20:15
  • yes, but this was already answered; I don't understand the edit? – Thomas Nov 03 '21 at 21:02

1 Answers1

5

I found an answer:

The class needs to get this attribute:

[System.ComponentModel.DesignerCategory("Code")]

I found this here: VS2010 opens my class-file (.cs) in the designer mode

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Thomas
  • 10,933
  • 14
  • 65
  • 136
  • Thanks - this did fix the problem for me, with VS2017. But it's just strange that this wasn't needed *until* I installed the optional VS2017 package which lets us create "Setup projects". Odd. – Mike Gledhill Aug 24 '17 at 13:10