Additional partial classes for a Form
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 for开发者_运维知识库m, not MainForm UI. It looks like VS2008 does not support multiple partial classes for a Forms. Is it possible to do that?
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.
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.
精彩评论