winformsvisual-studiodesigner

Form designer has became unavailable for a form in Visual Studio


After some work on form in Visual Studio 2015, form designer suddenly became unavailable.

Symptoms:

Why the Visual Studio is not evaluating form files as valid, not showing Designer view?


Solution

  • Fix: In source code of the form, manually move any classes below the class which defines the form. The form class must be the first class definition encountered when reading the source file from top to bottom.

    Details:

    I accidentally locked myself out, with error message written behind the locked door.

    Issue: During the work, I temporarily added a trivial helper class to the beginning of the form code file. If I had the designer open that time, I could have seen the following error:

    The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again.

    The catch is, the error shows only in the designer. If you have only code window open at the moment, you won't spot the error – and worse, you are no more allowed to enter the designer view to discover it.

    So a case can happen, when Visual Studio gives no clue – the only help is qualified guess and trial.