WinForm局部类 [英] WinForm partial classes

查看:126
本文介绍了WinForm局部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForm项目,其中包含一个名为MainUI的表单.您会看到自动生成的部分类显示为MainUI.cs下的一个节点.有没有办法将我自己创建的子类MainUI.Other.cs移动"到MainUI.cs下,使其显示为另一个节点?

I have a WinForm project that contains a form called MainUI. You can see that the automatically generated partial class shows up as a node under MainUI.cs. Is there a way to "move" my self created partial class MainUI.Other.cs under MainUI.cs so that it'll show as another node?

推荐答案

在Visual Studio中关闭解决方案,然后在文本编辑器中打开.csproj文件.找到MainUI.Other.cs,并添加以下XML元素:

Close the solution in Visual Studio, and open your .csproj file in a text editor. Find MainUI.Other.cs, and add the following XML element:

<Compile Include="MainUI.Other.cs">
  <SubType>Form</SubType>
  <DependentUpon>MainUI.cs</DependentUpon>  <!-- this is the magic incantation -->
</Compile>

在Visual Studio中重新打开解决方案,享受结节以下的好处.

Reopen the solution in Visual Studio and enjoy subnodular goodness.

也就是说,您可能需要重新考虑这是否是一个好主意. .designer.cs文件显示为子节点的原因是,您通常不需要或不想打开它,因为它包含生成的代码,您通常可以通过设计器查看或编辑该代码.部分类文件将包含您要编辑和查看的您的代码;如果在解决方案资源管理器中不容易看到该文件,则可能会使维护程序员感到困惑.但是,只有您才能知道适合您的项目的地方-只是要记住一点!

That said, you may want to reconsider whether this is a good idea. The reason the .designer.cs file is displayed as a subnode is because you won't normally need or want to open it, because it contains generated code which you'd normally view or edit through the designer. Whereas a partial class file will contain your code, that you'll want to edit and view; it may be confusing to maintenance programmers if the file is not easily visible in Solution Explorer. However, only you can know what's right for your project -- just something to bear in mind!

这篇关于WinForm局部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆