tags:

views:

28

answers:

1

We have a big Form class that we like to split into peaces using partial class approach

That could be done by manually modifying a project file, and adding MainFormPN.vb entry

<Compile Include="MainForm.vb">
  <SubType>Form</SubType>
</Compile>    
<Compile Include="MainForm.Designer.vb">
  <DependentUpon>MainForm.vb</DependentUpon>
  <SubType>Form</SubType>
</Compile>
<Compile Include="MainFormPN.vb">
  <DependentUpon>MainForm.vb</DependentUpon>
</Compile>

The issue with this approach is when double click on this item in VS2008 IDE it shows new empty form, not MainForm UI. It looks like VS2008 does not support multiple partial classes for a Forms. Is it possible to do that?

+1  A: 

Actually, using multiple partial class files will work fine. I've done it before (though I'm not proud to say that... if you've got a form so monolithic that it needs to be split into several files, maybe it's time to refactor your code).

The fact that the Windows Forms designer shows a blank form when you go to open the partial class is just an idiosyncrasy of Visual Studio. As long as you double-click on the "main" form file (in your case, MainForm.vb), it will display correctly.

In other words, don't worry; the code from your partial class files does indeed all belong to the same class.

Dan Tao
+1, don't mess with the plumbing, you'll have a wet floor.
Hans Passant