Visual Studio Design View - form is blank
Solution 1
Your project file has become invalid.
A valid project entry for a form looks like this:
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
Yours though is missing the DependentUpon line - which is why the code and designer files appear separately in the project, instead of being connected:
<Compile Include="mainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="mainForm.Designer.cs" />
If you add in the missing line, the form displays correctly in design mode:
<Compile Include="mainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="mainForm.Designer.cs">
<DependentUpon>mainForm.cs</DependentUpon>
</Compile>
And to tidy up the resource file:
<EmbeddedResource Include="mainForm.resx">
<DependentUpon>mainform.cs</DependentUpon>
</EmbeddedResource>
In order to fix this, you can just edit the csproj in an editor, or to do it in Visual Studio:
- Back up the files
- Right-click the project and choose "Unload Project"
- Right-click the unloaded project and choose "Edit [ProjectName].csproj"
- Make your changes, and close the file.
- Right-click the unloaded project and choose "Reload Project"
Solution 2
I solved the problem by removing all files associated with that form
- File -> Right-click -> Exclude from Project
and adding the files manually back to the project
- Project -> Add -> Existing Item...
Solution 3
For those searching around and finding no solace, I have another solution. The project I inherited has horrible code quality and the previous developer had mixed case all over his code because "It's case insensitive, so it doesn't matter"
So, while PopulateRevs
is, in fact, identical to POpulateREvs
in Visual Basic, that kind of laziness leads to issues. To wit:
<Compile Include="Inventory\Partmaster.Designer.Vb">
<DependentUpon>Partmaster.vb</DependentUpon>
</Compile>
<Compile Include="Inventory\Partmaster.vb">
<SubType>Form</SubType>
</Compile>
I happened to see this in the .vbproj
file while looking at other solutions that didn't work. I happened to change Partmaster.Designer.Vb
to Partmaster.Designer.vb
(lowercase extension) and it worked.
So as another solution, while Visual Basic is not case sensitive, it looks like the .vbproj
file is. If you're stumped, another thing to make sure is that your file names and .proj
files share the same case.
(I realize this is tagged C#
, but I tested this in C# and the mixed case will cause problems there as well.)
Comments
-
Daniel Bencik almost 2 years
I have a C# project with two forms. All compiles well. When I run the project, all forms are drawn as they are expected to.
A couple of days back, the DesignView of all forms started to shown nothing but a blank form, like the one you get in a new Windows.Forms project.
I went through several questions on SO with a similar problem, here are the comments to those questions:
- there are no 3rd party libraries that my project uses (apart from htmlAgilityPack, which does not cause this problem in other Windows.Forms C# projects)
- I have checked that the InitializeComponent function is only once in the project for each form
- When I create a new Project and add an existing form (i.e. one of my problematic project forms), the Design Viewer works as expected - hence I suspect that the .cs, .Designer.cs and .resx files of my forms are OK.
Is there something I could have messed up in the project settings or somewhere else?
EDIT
The third point above is misleading - I tried creating a new project for the second form as well and there the problem persist. The minimal amount of source code that shows the problem is to to be found here.