抱歉 P.Brian.Mackey,您的解决方案对我不起作用。它确实通过让 VS 识别它是一个表单而不是一个代码文件来改进它,即给它是 Icon(想象它添加了表单)
但我设法完全解决问题的唯一方法是在文本编辑器中手动编辑 csproj 文件。我不太相信这是一个很好的解决方案并且可能非常危险,特别是考虑到我犯了两个打字错误并完全破坏了项目,但一旦我做对了它就可以工作。也很难发现没有正确关闭标签或忘记文件扩展名等错误。
因此,在通过“添加 --> 现有项目”添加文件后,该项目从这些条目开始:(Ps 我确定您不必先将文件复制到项目文件夹中,只需导航到它们存储在项目之外,VS会将它们复制到您右键单击的文件夹中。当然也可以提前复制。)
<Compile Include="Reports\GBudget1Report.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Reports\GBudget1Report.Designer.cs" />
<Compile Include="Reports\GBudget2Report.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Reports\GBudget2Report.Designer.cs" />
<Compile Include="Reports\LASHForm.cs">
<SubType>Form</SubType>
</Compile>
在文件的更下方:
<EmbeddedResource Include="Reports\GBudget1Report.resx" />
<EmbeddedResource Include="Reports\GBudget2Report.resx" />
将这些与项目中工作正常的现有表单进行比较(另一个选项是,如果您没有,则在 Visual Studio 中创建一个新表单,它会为您提供正确的标记以进行复制) 我发现 DependentUpon 标记没有将子文件关联到主表单代码文件。
所以我手动编辑它以匹配:
<Compile Include="Reports\GBudget1Report.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Reports\GBudget1Report.Designer.cs">
<DependentUpon>GBudget1Report.cs</DependentUpon>
</Compile>
<Compile Include="Reports\GBudget2Report.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Reports\GBudget2Report.Designer.cs">
<DependentUpon>GBudget2Report.cs</DependentUpon>
</Compile>
再次深入文件:
<EmbeddedResource Include="Reports\GBudget1Report.resx">
<DependentUpon>GBudget1Report.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Reports\GBudget2Report.resx">
<DependentUpon>GBudget2Report.cs</DependentUpon>
</EmbeddedResource>
这不是我喜欢的解决方案,但它有效。如果有人有更好的解决方案,我很乐意倾听。