tags:

views:

1086

answers:

3

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.

+4  A: 

I'm pretty sure you don't have to specify all inheritances for a partial class. So if you just drop System.Windows.Forms.Form from the inheritance list for the DoCommands.cs file you should be golden.

Edit: Also, given the size of your main form, you might want to consider refactoring. Consider following a MVC or MVP pattern. Separate your concerns into separate classes and possibly even modules.

Randolpho
Nope. Removing 'System.Windows.Forms.Form' from the DoCommands.cs file did not change anything. VS2008 still marks it with a GUI form icon and treats it as such. :(And while I do agree that refactoring the design to use MVC, et al., is the better way, for now time limits hinder a complete redesign of such.
Sebastian Dwornik
+1  A: 

Your partial form extension don't need to inherit from System.Windows.Forms.Form - just like your PipeServerform.designer.cs do not inherit it.

HuBeZa
+1  A: 

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.

Fredrik Mörk
When I re-load the solution, VS2008 reinserts the '<SubType>Form</SubType>' text back into the project file for the 'DoCommands.cs' lines, and the GUI blank form still exists within it. But at least it's listed under the 'mainform.cs' tree within the project file. I guess that's the best we can hope for.
Sebastian Dwornik