4

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?

John
  • 29,788
  • 18
  • 89
  • 130
volody
  • 6,946
  • 3
  • 42
  • 54

2 Answers2

2

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
  • 125,917
  • 54
  • 300
  • 447
  • 1
    @HansPassant , I do pretty much all my work in the same Class, and it´s a mess. But it works, and when use other classes to separate work, it just goes slower and i have to call the classes which is just irritating. But at the end of the day, it works, so is there any problem except much code in one place? – Zerowalker Aug 28 '13 at 22:53
0

Another possible approach to would be to encapsulate groups of functionality into user controls. This will encapsulate logic, make the code easier to manage (if done right), and allow you the same effect without the goofiness of VS and partial form classes in terms of the GUI designer.

Brian M.
  • 826
  • 1
  • 8
  • 16