C# 无法使用带有 Visual Studio 2010 的 Windows 窗体获取设计器视图窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10941692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to get the designer view window back using windows forms with Visual Studio 2010
提问by user1443434
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:
我正在使用 Visual Studio Express 2010 ENU SP1 编写 C# Windows 窗体应用程序。进一步的 VS 细节在这篇文章的底部。我最近使用设计器视图对布局进行了一些更改,然后决定我不想要这些更改,所以我关闭了设计器窗口。当我关闭项目并且更改以任何方式保存时,代码窗口仍然打开。我不关心更改,因为布局可以轻松恢复,除了我找不到任何方法重新打开可视化设计器窗口。为了恢复窗口,我尝试了以下操作:
Shift F7
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
我有一份 VS 2010 团队的评估副本,它在使用我的项目时显示完全相同的行为
I have tried a backup copy of the project but it displays the same problem in both the Express and Team versions
我已经尝试了该项目的备份副本,但它在 Express 和 Team 版本中都显示了相同的问题
I have been all over the MSDN, VS forum, and the internet at large and not found any solutions
我已经遍及 MSDN、VS 论坛和整个互联网,但没有找到任何解决方案
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:
当我第一次启动项目时,我确实从解决方案资源管理器中重命名了 Form1.cs 文件,因为我希望应用程序的名称与 Form1 不同。执行此操作时,它询问以下内容:
"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.
我回答是的。所以现在我没有 Form1.cs 文件,而是一个包含“projectname.cs”的文件和名为“projectname.Design.cs”的设计器文件。这是我所做的唯一我能想到的更改相关。我确实尝试将它重命名回 Form1.cs 但这也没有解决问题。
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.
我不得不说我是使用 Visual Studio 的新手。到目前为止,我相当喜欢它,但我现在已经死在水里了,除非我能解决这个问题,否则我将失去两周的工作。任何帮助将不胜感激。
Thanks, -Tom
谢谢,-汤姆
Additional Details:
额外细节:
Windows 7 Professional SP1 32 bit x86
Windows 7 专业版 SP1 32 位 x86
Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel Microsoft .NET Framework Version 4.0.30319 SP1Rel
Microsoft Visual Studio 2010 版本 10.0.40219.1 SP1Rel Microsoft .NET Framework 版本 4.0.30319 SP1Rel
Installed Version: C# Express
安装版本:C# Express
Microsoft Visual C# 2010 01014-169-2560017-70726 Microsoft Visual C# 2010
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.
Microsoft Visual C# 2010 Express - ENU Service Pack 1 (KB983509) KB983509 此 Service Pack 适用于 Microsoft Visual C# 2010 Express - ENU。如果您稍后安装更新的服务包,此服务包将被自动卸载。
回答by user1443434
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.
谢谢你的想法。我刚刚完全重新安装了 VS 2010 团队版本的 Express 和评估副本,现在它神奇地工作了。我不知道是什么导致了这个问题,也不知道是什么解决了它,但我现在回到了正轨。在这个论坛上提问之前,我可能应该这样做。
回答by threads
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.
我现在意识到这是一个很老的话题,但我刚刚在 VS2010 的一个项目中发生了类似的事情。无法在表单设计器中编辑表单。
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 ...
最后将其追溯到 .csproj 文件中的问题。有一个项目组指定编译的内容。在项目组标签中,对于我的表单,它有...
<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.
缺少 SubType XML 标记。快速更改项目文件,我可以再次编辑表单。
回答by David
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.
我正在使用 VS2012,当我将一个库控件复制到一个单独的库中以进行进一步开发时遇到了问题。运行时表单中的所有控件都显示完美,但设计器显示了一个空白表单。
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:
问题不像上面那样(那是完整的),但是,由于这个提示,我添加了一个新表单并比较了 .csproj 文件中的条目。对于每个复制的表格,都显示了类似于以下内容的条目:
<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.
为每个表单手动添加这些解决了这个问题。
回答by GrandMasterFlush
I had the same problem but mine was caused on VS2012 by dragging and dropping some of the forms into different folders.
我遇到了同样的问题,但我的问题是在 VS2012 上通过将一些表单拖放到不同文件夹中引起的。
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 Includeline should read like this:
如果您在子文件夹中有表单,则该Compile Include行应如下所示:
<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 行以关联 resx 文件:
<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.
再次注意,第一行提到了子文件夹,而第二行没有。
回答by Nick Alexander
I realise this is a reallyold thread now, but I had the same problem and it turns out there is anothernode 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.
我现在意识到这是一个非常老的线程,但我遇到了同样的问题,结果发现csproj 文件中还有另一个节点可能会误入歧途;表单 .resx 有一个 EmbeddedResource 节点,我的缺少子节点设计器。这让我可以在 IDE 中再次看到表单代码。
回答by Amati
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.
事实证明,即使一切正常并且没有错误,您也不能将 SomeStruct 定义放在那里。一旦我移动它,我就能够再次看到设计器视图。
回答by Peter
I had the same problem with VB. Thanks for the hints. I found the same issues in the .vbproj with my UserControl.
我在 VB 中遇到了同样的问题。感谢您的提示。我在 UserControl 的 .vbproj 中发现了同样的问题。
I had this in the .vbproj file:
我在 .vbproj 文件中有这个:
<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
ps - 我正在使用 vs Community 2015
回答by Mick
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.
我将一个表单从一个项目复制到另一个项目(使用 Windows 资源管理器),然后通过右键单击 VS 中的项目并选择 > 添加 > 现有项目将其添加到新项目中。
My mistake was to add all three files for the form (.cs, .designer.cs and .resx). I should have only added the .cs file.
我的错误是为表单添加了所有三个文件(.cs、.designer.cs 和 .resx)。我应该只添加 .cs 文件。
回答by Vijay Bansal
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.
确保在设计器部分类之前没有声明任何类。.cs 文件需要将部分设计器类作为文件中的第一个类。
public partial class frmWidget : Form
{
}
public class SomeClass
{
}
Now SomeClasscannot be on top of the partial frmWidgetclass. 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.
现在SomeClass不能位于部分frmWidget类之上。重新安排后,它将自动修复设计器问题,无需重新启动 VS 或重新创建表单。我希望这有帮助。
回答by vaheeds
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.dllassembly. Then I add the reference and now the designer shows up.
我遇到了同样的问题,但我为我的Form. 在我意识到用于 WinForms 的 RadControls 的设计时功能是在Telerik.WinControls.UI.Design.dll程序集中实现之前,我无法看到设计器。然后我添加引用,现在设计师出现了。

