Matthias Meid
Matthias Meid

Reputation: 12521

Additional Code File for Windows Forms Form

Can I add another code file to a Windows Forms Form so that it appears below the form in the Solution Explorer?

If I just add another file with this name, it isn't files below MyWindow. Moreover, it is displayed with a Form icon. My code file has grown huge, that is why I'd like to split it up.

Cheers Matthias

Upvotes: 0

Views: 371

Answers (2)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

The correct solution would be to extract helper classes.
But you can simply add a new class file (not a new windows forms file) and save your project. Open the csproj file in a text editor and locate the <Compile Include="yourNewFile.cs"> tag of the newly added file. Inside this tag, add a new tag <DependentUpon>YourParent.cs</DependentUpon>, where YourParent.cs is the file you want to put the new file under. Save the csproj file and switch back to VS and reload the project file.

Upvotes: 1

foxy
foxy

Reputation: 7672

Although there isn't a way to do that, you could add the two form (and associated code files) into a folder, which in essence, achieves the same effect.

I'd also like to mention that under "good class design", you'd refractor and separate your code out so that it is more easily maintainable and easier to follow. You may have heard of these, but principles like "separation of concerns", "DRY" and "unit of work" really make a difference if and when your application becomes fat and gains another 1,000,000 lines of code.

Upvotes: 1

Related Questions