C# windows窗体中丢失的设计视图

C# windows窗体中丢失的设计视图,c#,windows-forms-designer,C#,Windows Forms Designer,我有一个C#windows窗体项目,在添加自定义控件时,我丢失了设计视图(没有错误,只是为空-在运行时工作正常) 我添加了此自定义NumericUpDown控件: 当我这样做时,我得到一个错误,说EventHandlerService已经存在,所以我通过删除bin和obj文件夹修复了它: 现在,当我编译时,不会出现错误,当我运行时,我的表单看起来很完美,但是form.cs[Design]页面是空的。它显示标准的空白页信息,上面写着“要向类中添加组件…”当我检查.cspropj时,一切看起来都

我有一个C#windows窗体项目,在添加自定义控件时,我丢失了设计视图(没有错误,只是为空-在运行时工作正常)

我添加了此自定义NumericUpDown控件:

当我这样做时,我得到一个错误,说EventHandlerService已经存在,所以我通过删除bin和obj文件夹修复了它:

现在,当我编译时,不会出现错误,当我运行时,我的表单看起来很完美,但是form.cs[Design]页面是空的。它显示标准的空白页信息,上面写着“要向类中添加组件…”当我检查.cspropj时,一切看起来都正常:

<ItemGroup>
    <Compile Include="Form1.cs">
      <SubType>Component</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <EmbeddedResource Include="Form1.resx">
      <DependentUpon>Form1.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <ItemGroup>

组成部分
表格1.cs
表格1.cs
ResXFileCodeGenerator
Resources.Designer.cs
设计师
符合事实的
Resources.resx
设置单个文件生成器
Settings.Designer.cs
符合事实的
设置。设置
符合事实的
我将Form1.cs子类型从“Component”更改为“Form”,但在重新编译时,该子类型又更改为“Component”

此外,我还可以通过代码继续在Form.Designer.cs页面中添加控件,这些控件将在运行时显示,但如果没有工具箱和拖放功能,这将是一项非常具有挑战性的任务


我还可以尝试其他什么方法恢复设计视图?

修复了该问题。自定义控件是一个单独的类,但我将其放在Form.cs类中,因此设计者感到困惑。我只需要将它拉到它自己的单独类中。

设计器是否处理新表单?我希望您在进行更改以回滚(如果需要)之前在源代码管理方面有一个良好的承诺。您可以做的另一件事是确保在表单构造函数中调用InitializeComponent。你看过表格的resx文件了吗?它是否仍然包含所有布局和控件?当我删除/注释自定义控件时,表单设计会重新出现。在我使用的form.desginers.cs类中有一个标准的InitializeComponent。我刚刚查看了resx文件,比较了带有和不带自定义控件的resx,结果看起来是一样的(但是没有显示设计中的自定义控件),所以我猜resx在这里做的不多?