Windows Forms 2.0 Programming (Microsoft .NET Development Series)

One of the big features provided by MFC is the ability to automatically generate basic application frameworks out of the box, including both SDI and MDI applications. However, Windows Forms 2.0 has evolved well beyond Windows Forms 1.x to provide more of the fundamental elements you need to match the default MFC-generated output from a functional point of view. Additionally, several components covered in this book make it that much easier.

To compare Windows Forms with MFC, I set out to create a Windows Forms equivalent of a vanilla MFC wizard-generated MDI text editor application, using what was available in .NET, Windows Forms, and this book. The result is shown in Figure B.9.

Figure B.9. A Windows Forms Equivalent of an MFC-Generated MDI Application

To create this application, I drew on the following pieces provided by Windows Forms, .NET, and this book:

  • VS05 to create a new Windows Forms project

  • MDI parent form (generated by VS05)

  • A blank form as the basis for the MDI child form (generated by VS05)

  • About box (generated by VS05)

  • FileDocument component (from Appendix F)

  • MRUMenuManager component (from Appendix F)

  • Tool strip, menu strip, and text box controls (from .NET)

  • DragAndDropFileComponent component (from Appendix F)

  • WindowsFormsApplicationBase for single instancing (from .NET)

  • Help compiler and System.Windows.Forms.Help (from vendor and .NET)

  • Application and user settings system (from .NET)

  • NTCOPYRES and a C++ .DLL project to generate and incorporate additional document icon resources into the application (from Chapter 13)

  • PrintDialog, PrintPreviewDialog, PageSetupDialog, PrintDocument, and PageCountPrintController (from both .NET and Chapter 8: Printing)

To pull these pieces together, I had to provide additional configurations and custom code:

  • Writing code to integrate form navigation

  • Configuring user settings to remember MDI parent form size and location from one application session to the next

  • Removing document-specific tool strip and menu strip controls from the generated MDI parent form and adding them to the MDI child form

  • Configuring menu and tool strip merging for MDI

  • Writing code to operate all printing components and to print a basic text document

  • Configuring FileDocument, MRUMenuManager, and DragAndDropFile Component

  • Creating and integrating help

  • Configuring C++ resource project, including importing appropriate icon resources and writing two lines of script in the post-build event of the DocApp sample to inject additional icon resources into the DocApp executable from the C++ resource DLL using NTCOPYRES

  • Writing code to support single-MDI application requirements (from Chapter 14: Applications)

Overall, I wrote just over 200 lines of code and 2 lines of post-build event script, to make it all work. Although MFC wins on the no-code front, if you start with the samples provided with this book, you should be off and running when starting your SDI or MDI document-based Windows Forms applications.

Also, when I was finished with the Windows Forms version of my MFC-like application, I gained access to several orders of magnitude more functionality in the .NET Framework Class Libraries than was ever provided in MFC.

Категории