'Add partial form class below windows form node

I'm currently facing the issue that my main Form.cs file grows bigger and bigger and I would like to split it into several partial files. These should stick below the main Form (MainForm.cs) Node in the Visual Studio Solution Explorer.

I tried creating the new class file and declared it a partial source file of my MainForm class. However, the newly created partial class file changes it's icon, looking like a form. It instead should stick below the MainForm Node in the Solution Explorer.

To visualize the problem:

Wrongly ordered partial class file

The MainForm.ContextActions.cs file content is as follows:

namespace Interface_Group_Editor
{
    public partial class MainForm
    {
        [...]
    }
}

The content is similar to the MainForm.Designer.cs file. However the .Designer.cs file sticks below the MainForm.cs node while .ContextActions.cs does not!

I only handle absolutely necessary form events in the MainForm.cs file and have my business logic in external classes that I access from the form. However, alone my TreeView code to maintain and edit the form takes about 500 lines of code which could be relocated to a new partial source file. This would help the whole visibility of the Project Structure a lot!

Is there any way to force this behavior to the Solution Explorer?



Solution 1:[1]

I'm not sure if I really wanted to do this however it works in some fashion for separating the Form code to do some Business logic (or other) code as this post was trying to do. I didn't like that it opened an Empty Form Designer on opening the file.

If you do Hans solution, but change the name of the file to MainForm.SomeExtensionClassYouWant.Designer.cs it no longer opens false Designer on double-clicking the file.

ie: there must be some code on opening when ending with .Designer.cs (or .vb) to open in code rather than the misleading designer.

Tested in VS 2017 in C# and VB.Net

EG:

<Compile Include="Form1.IncludedPartial.Designer.cs">
  <DependentUpon>Form1.cs</DepedentUpon>
</Compile>

Solution View with Partial Form Class under Form

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CooPzZ