WinForm partial classes

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>

Reopen the solution in Visual Studio and enjoy subnodular goodness.

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!


Yes, this is possible, but you will have to hand edit the project file.

In the project file (open it with the XML Editor) locate the file listing item group. In my example, I left the form as "Form1.cs". Add the child element "<DependentUpon>" to your extended class as per the example below:

 <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="Form1.Designer.Other.cs">
      <DependentUpon>Form1.cs</DependentUpon>
      <SubType>Form</SubType>
    </Compile>

Typically though you wouldn't want any non-generated code to be hidden as a child node though. My normal practice is to create a folder in the project called "Partial Classes" and add them all in the same location.