Unable to get the designer view window back using windows forms with Visual Studio 2010
Asked Answered
N

15

26

I am in process of writing a C# Windows Forms application using Visual Studio Express 2010 ENU SP1. Further VS specifics are at the bottom of this post. I recently made some changes using the designer view to the layout and then decided that I did not want the changes so I closed the designer window. The code window was still up when I closed the project and the changes were saved any way. I don't care about the changes because the layout can be restored easily except for the fact that I cannot find any way to reopen the visual designer window. To get the window back I have tried the following:

Shift F7

Right click in the designer code window

Double click the designer file under the solution explorer

Select the designer file under the solution explorer and use the context menu to bring up the file

I have an evaluation copy of the VS 2010 Team and it displays exactly the same behavior when utilizing my project

I have tried a backup copy of the project but it displays the same problem in both the Express and Team versions

I have been all over the MSDN, VS forum, and the internet at large and not found any solutions

When I first started the project I did rename the Form1.cs file from within the solution explorer because I wanted to have a different name than Form1 for the application. When doing this it asked the following:

"You are renaming a file. Would you like to perform a rename in this project of all references to the code element 'projectname'?

I replied yes. So now I don't have a Form1.cs file but a file with my "projectname.cs" and the designer file named "projectname.Design.cs. This is the only change that I made that I can think of that might be relevant. I did try renaming it back to Form1.cs but that also did not resolve the problem.

I have to say that I am new to using Visual Studio. So far I like it quite a bit but I am dead in the water right now and unless I can get this resolved I will lose two weeks worth of work. Any assistance would be greatly appreciated.

Thanks, -Tom

Additional Details:

Windows 7 Professional SP1 32 bit x86

Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel Microsoft .NET Framework Version 4.0.30319 SP1Rel

Installed Version: C# Express

Microsoft Visual C# 2010 01014-169-2560017-70726 Microsoft Visual C# 2010

Microsoft Visual C# 2010 Express - ENU Service Pack 1 (KB983509) KB983509 This service pack is for Microsoft Visual C# 2010 Express - ENU. If you later install a more recent service pack, this service pack will be uninstalled automatically.

Norahnorbert answered 8/6, 2012 at 0:29 Comment(3)
have u tried making a new form and copy-all, paste it into the new form overwriting the pregenerated stuff?Shebeen
Hard to say without looking at the code. But is the partial class in the .design.cs file named the same as the class in the regular .cs? Usually you would get an error if not, but it is worth a check...Weisman
just right click on InitializeComponent(); and Go To Declaration or F12. Otherwise you've probably learnt by now you need source control and this actually means something: /// do not modify the contents of this method with the code editor.Prevocalic
E
46

I realise this is quite an old thread now, but I just had something similar happen in one of my projects in VS2010. There was no way to edit the Form in the form designer.

In the end tracked it down to a problem in the .csproj file. There is a item group that specifies what is compiled. Within the item group tag, for my form it had ...

<Compile Include="AreaChart.cs" />

it needed...

<Compile Include="AreaChart.cs">
  <SubType>Form</SubType>
</Compile>

The SubType XML tag was missing. A quick change to the project file and I could edit the form again.

Exerciser answered 28/5, 2013 at 2:46 Comment(5)
This solved the same issue for me in VS2015. THANKS!Allx
Does anyone know why VS does this? [remove the sub-type tags]Toile
I have the <SubType>Form</SubType> in my project file, but it doesn't show up yet.Fieldstone
I just wanted to comment on this solution as this is still a solution in VS 2019 version 16.11.4 I don't know how, but the View Design option simply disappeared on me and I could no longer access the WinForms Designer. I don't know why would I would lost the <SubType> tags, but once I added them in everything worked fine. Checking the git history and sure enough a change made had removed the SubTypes at one point.Susa
@Susa Same thing happened to me with VS 2019 16.11.25. Had to paste <SubType>Form</SubType> into a huge project file. =(Romonaromonda
T
28

Just one more way to screw up the form designer - I had something like this:

namespace MyProgram
{
    public struct SomeStruct {
        int a,b;
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}

Turns out you can't put the SomeStruct definition there even though everything works fine and there were no errors. Once I moved it, I was able to see the designer view again.

Tabaret answered 7/10, 2015 at 14:34 Comment(2)
I had the same problem except it was a classGilbye
The form class needs to be the first thing in the file. All other definitions need to be in the end of the file.Pily
H
17

Again it is an old thread but web interest indicates that numerous people are still having this problem and it has not been solved.

I am using VS2012 and had the problem when I copied a library control which spawns 3 forms into a separate library for further development. All controls in the forms displayed perfectly when run but the designer displayed a blank form.

The problem was not as above (that was intact) but, thanks to this hint, I added a new form and compared the entries in the .csproj file. For each of the copied forms, an entry akin to the following was showing:

<Compile Include="MyForm.Designer.cs" />

What was needed was:

<Compile Include="MyForm.Designer.cs">
    <DependentUpon>MyForm.cs</DependentUpon>
</Compile>

Adding these manually for each form solved the problem.

Hazardous answered 6/12, 2013 at 12:50 Comment(3)
Thanks for your answer, it helped solved my problem though I encountered another issue relating to sub-folders I had to fix which I've mentioned below.Phrasal
My .csproj contains this lines but I still can't find/open the designer.Intramural
Solved my problem.Lashley
T
13

Make sure you don't have any class declared before your designer partial class. The .cs file needs to have the partial designer class as the first class in the file.

public partial class frmWidget : Form
{
}

public class SomeClass
{
}

Now SomeClass cannot be on top of the partial frmWidget class. Once you re-arrange that then it will automatically fix the designer issue and no need to restart VS or re-create the form. I hope this helps.

Thrombosis answered 25/10, 2016 at 15:7 Comment(1)
New to C#/WinForms, this solved it for me, VS2017 Community.Florinda
P
10

Tried all the suggestions mentioned in this question, nothing worked for Visual Studio Community 2017

  • no Shift-F7 shotcut
  • no context menu item visible
  • no double clicking on MainForm.cs
  • no wrong class order inside MainForm.cs
  • no wrong entries in mysolutionname.csproj file

But this worked for me

  1. Right click your MainForm.cs file (or 'Form.cs' depending how you named it)
  2. 'Exlude from project'. This temporarily removes MainForm.cs, MainForm.Designer.cs and MainForm.resx
  3. Use 'Add » Existing item' and select MainForm.cs. This will re-include all three files.
    Of course you should add them back to the same folder as they were before
  4. Double click on MainForm.cs and Design view magically openes
Pome answered 4/12, 2017 at 21:55 Comment(0)
P
3

I had the same problem but mine was caused on VS2012 by dragging and dropping some of the forms into different folders.

David's solution above was helpful towards fixing it, but didn't go all the way.

If you have the form in a sub-folder the Compile Include line should read like this:

<Compile Include="SubFolderName\MyForm.Designer.cs">
    <DependentUpon>MyForm.cs</DependentUpon>
</Compile>

Please note that the sub-folder name is needed in the first line but not in the second line.

I also had to change the EmbeddedResource line further down the file to associate the resx file:

   <EmbeddedResource Include="SubFolderName\MyForm.resx">
        <DependentUpon>MyForm.cs</DependentUpon>
    </EmbeddedResource>

Again, note that the first line mentions the sub-folder whereas the second line doesn't.

Phrasal answered 21/2, 2014 at 15:23 Comment(0)
N
2

Thanks for the thoughts. I just completely reinstalled both the Express and evaluation copies of the Team versions of VS 2010 and it is now magically working. I have no idea what caused the problem nor what fixed it but I'm now back on track. I probably should have done that before asking on this forum.

Norahnorbert answered 8/6, 2012 at 8:41 Comment(1)
Congrats on the fix; it doesn't matter how simple it might have seemed to resolve, StackOverflow exists to help us learn! When you are able, please make sure to mark your answer as 'accepted' so that others will be able to learn from your success. Cheers~Flintlock
P
2

I had the same problem with VB. Thanks for the hints. I found the same issues in the .vbproj with my UserControl.

I had this in the .vbproj file:

<Compile Include="AddCommunicationTask.vb" />

And changed it to this:

<Compile Include="AddCommunicationTask.vb">
   <SubType>UserControl</SubType>
</Compile>

When I reloaded it I was still having problems and realised that I had written another class in above the form class, this was causing the error. The form class must be first. All I had to do was move my class down and make the form class the top one.

I hope this helps others - good luck!

p.s - I am using vs Community 2015

Ptolemy answered 7/5, 2016 at 16:8 Comment(0)
P
2

I had the same issue since I had created the project as a C# Windows Form App (.NET Core) I decided to create it as a C# Windows Form App (.NET Framework) and I can now see and use the Designer. Note the difference between using 'Core' vs 'Framework'

I hope this helps you out.

Phlogistic answered 9/10, 2019 at 10:11 Comment(1)
.Net Core have it's own Designer which you have to install separately. More info: devblogs.microsoft.com/dotnet/…Penance
M
0

I realise this is a really old thread now, but I had the same problem and it turns out there is another node that can go astray in the csproj file; the form .resx has an EmbeddedResource node and mine was missing the subnode Designer. This allowed me to see the form code again in the IDE.

Mimosa answered 10/6, 2015 at 3:59 Comment(0)
P
0

I had a similar issue, but not quite the same.

I copied a form from one project to another (using windows explorer) and then added it to the new project by right clicking on the project in VS and choosing > Add > Existing Item.

My mistake was to add all three files for the form (.cs, .designer.cs and .resx). I should have only added the .cs file.

Psyche answered 25/6, 2016 at 14:39 Comment(0)
F
0

Although this is quite an old thread, I want to share my case and the solution.

I had the same problem but I used Telerik WinForms component for my Form. I couldn't see the designer until I realize that the design-time capabilities of RadControls for WinForms are implemented in the Telerik.WinControls.UI.Design.dll assembly. Then I add the reference and now the designer shows up.

Fieldstone answered 1/4, 2017 at 11:32 Comment(0)
G
0

I had the same problem and I got the (Design) window back by double clicking the Form1.cs file in the Solution Explorer (not the Form1.Designer.cs file).

Gymnasium answered 6/8, 2017 at 1:22 Comment(0)
G
0

I accidentally deleted my Form1[Design] file. Double clicking the Form1.h file did nothing. The program ran and the Buttons TextBoxes and Labels were all there just no Form1[Design] was visible to edit. I fixed it Under: Header Files select Form1.h and go to Form1.H file properties. Under File Type from the drop down change it to "C++ Form" I closed and restarted the program. You should now be able to double click Form1.h and see your Form1[design].

Greta answered 17/2, 2018 at 0:39 Comment(0)
L
0

I had the same issue in VS 2010. I was not able to view the designer form(Connect.CS).

i already had the

<Compile Include="Connect.cs">
  <SubType>Code</SubType>
</Compile>
<Compile Include="Connect.Designer.cs">
  <DependentUpon>Connect.cs</DependentUpon>
</Compile>

tags in the ItemGroup Tag, but still i wasn't able to view the Designer.

I was using name space directive 'Using RFCOMAPILib', which already had a Form element in it and it clashed with the System.Windows.Forms.Form.

After replacing 'public partial class Connect : Form' to 'public partial class Connect : System.Windows.Forms.Form' im able to view the Designer now.

Lunchroom answered 3/11, 2019 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.