如何在 Visual Studio 中打开表单设计器?

Swi*_*had 13 c# visual-studio

我正在尝试在 Visual Studio 中使用 C# 创建 Windows 窗体应用程序。

一般情况下可以双击Form1.cs在解决方案资源管理器中双击该文件,以访问简单的拖放设计器。

不幸的是,它只打开文件的代码。

解决方案浏览器

Ale*_*xan 9

您位于文件夹视图中。

更改为解决方案(项目)视图。

这个图标在此输入图像描述在解决方案资源管理器的顶部。


wla*_*r86 8

在表单类之前放置另一个类(在本例中是我的ImageContainer类)时遇到同样的问题。

namespace ImageProcessor
{
    internal class ImageContainer
    {
    }
    
    public partial class Form1 : Form
    {
        private ImageContainer m_img = null;
    }
}
Run Code Online (Sandbox Code Playgroud)

只需将VS2019 拖放设计器移动internal class ImageContainer到后面即可加载我的 Form1 类。public partial class Form1 : Form { }

namespace ImageProcessor
{
    public partial class Form1 : Form
    {
        private ImageContainer m_img = null;
    }

    internal class ImageContainer
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

解决方案资源管理器中的符号也更改回对话框图标。

  • 接得好。真的让我很生气,这是一个事情...... (2认同)

Gab*_*uci 3

文件之间的关联肯定以某种方式被破坏了。您可以手动编辑 .csproj 文件并更正它。搜索Form1。每个文件都应该有如下所示的条目:

<Compile Include="Form1.cs">
  <SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
  <DependentUpon>Form1.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Form1.resx">
  <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Run Code Online (Sandbox Code Playgroud)

注意SubTypeDependentUpon。这些是重要的部分。