Windows窗体中丢失的设计视图

时间:2021-07-30 21:11:03

I have a C# windows form project where on adding a custom control, I lost the design view (no error, just empty - works fine during runtime).

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

I added this custom NumericUpDown control: http://www.codeproject.com/Articles/29244/A-Derived-NumericUpDown-that-Provides-Handlers-for

我添加了这个自定义的NumericUpDown控件:http://www.codeproject.com/Articles/29244/A-Derived-NumericUpDown-that-Provides-Handlers-for

And when I did that I got an error saying an EventHandlerService already exists so I fixed it by removing the bin and obj folders: http://www.csharp411.com/ieventhandlerservice-already-exists-in-the-service-container/

当我这样做时,我得到一个错误,说EventHandlerService已经存在,所以我通过删除bin和obj文件夹来修复它:http://www.csharp411.com/ieventhandlerservice-already-exists-in-the-service-container/

Now, when I compile, I don't get an error and when I run, my form looks perfect but the Form.cs[Design] page is empty. It displays the standard empty page information that says "To add components to your class ..." When I check the .cspropj, everything looks ok:

现在,当我编译时,我没有收到错误,当我运行时,我的表单看起来很完美,但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>

I changed the Form1.cs subtype from "Component" to "Form" but on recompiling that changes back to "Component".

我将Form1.cs子类型从“Component”更改为“Form”,但在重新编译时将其更改回“Component”。

Also, I can continue to add controls in the Form.Designer.cs page via code and the controls will show up during runtime but that's very challenging without the toolbox and the ability to drag-drop.

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

What other things can I try to get back the design view?

还有什么其他的东西我可以尝试回到设计视图?

1 个解决方案

#1


Fixed the issue. The custom control was a separate class but I put it in the Form.cs class so the designer got confused. I just had to pull it out to its own separate class.

修复了这个问题。自定义控件是一个单独的类,但我把它放在Form.cs类中,所以设计师感到困惑。我只是把它拉到自己独立的班级。

#1


Fixed the issue. The custom control was a separate class but I put it in the Form.cs class so the designer got confused. I just had to pull it out to its own separate class.

修复了这个问题。自定义控件是一个单独的类,但我把它放在Form.cs类中,所以设计师感到困惑。我只是把它拉到自己独立的班级。