Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: splitting a class into multiple files (with a form)

Tags:

c#

file

Using: C#, VS2008

I have the following main form class:

[Main.cs]

namespace Server
{
   public partial class PipeServerform : System.Windows.Forms.Form
   {
   ...
   }
}

But it's big, and long, and contains GUI + logic code.

So I seperate the class into multiple files for easier management and create this file that only holds the logic details:

[DoCommands.cs]

namespace Server
{
   public partial class PipeServerform : System.Windows.Forms.Form
   {
   ...
   }
}

This works... BUT! The 'DoCommands.cs' file within the VS2008 project now has a default blank GUI 'form' window associated with it.

It makes sense, as it's still part of the main form class, but I assumed the separation between different files would inform VS2008 that it is simply a logic file holder of simply commands, and doesn't contain any GUI form code.

Is there an easy way to solve this view? Such that the 'DoCommands.cs' file doesn't have the associated blank GUI form with it?

Or do I have to literally split it into different classes?

Thanks.

like image 828
Sebastian Dwornik Avatar asked Aug 20 '09 13:08

Sebastian Dwornik


1 Answers

If order to get it to subordinate itself under PipeServerForm, open the project file in a text editor. You will find a block looking like this:

<Compile Include="DoCommands.cs">
  <SubType>Form</SubType>
</Compile>

Change it into this:

<Compile Include="DoCommands.cs">
  <DependentUpon>Main.cs</DependentUpon>
</Compile>

Now, when you load the project, DoCommands.cs should appear under Main.cs, just as Main.Designer.cs. I did note that VS seem to add the SubType element automatically, so that DoCommands.cs will still open in the Forms Designer by default. Perhaps there is a simple solution around for that as well.

like image 52
Fredrik Mörk Avatar answered Oct 03 '22 16:10

Fredrik Mörk