How to create a WinForms MDI application? - part 4
It is my last post of the series. The post before this focused on the custom classes developed to support Presentation Layer of the sample application. A group of classes of input data validation has been presented. Another two classes for managing forms and central managing of exceptions were provided.
(All posts in this series: Post 1, Post 2, Post 3, Post 4, Source Code)
Today, I’ll present the rest of the sample application.You can have look at application file structure on the picture below.
Application classes and forms’ classes are logically grouped in different folders. In the reports folder we have a CrystalReports template file with the report view needed to present maintenance done of the individual car and a form which displays the report. Next up is Common folder that groups base classes described in my third post of the series. BaseForm is described below. We come to CarManagement folder that groups two forms classes one for listing all cars and one for managing new and existing cars. The last folder is CarMaintenanceManagement that contains forms related to cars’ maintenance management.
As I mentioned in my previous posts it is a sample of MDI application. Consequently, we need a windows form to be a MDI container (MDI parent form). MainForm form is the MDI container in this application. All forms are opened into it except of ManageCarForm, ManageCarMaintenanceForm and CreateCarsFleetSpotChecksMaintenanceForm which are opened as a dialog. ViewCarsDetailsForm can be opened only once into MDI container but ViewCarMaintenancesForm can be opened per each car into MDI container. It is done by FormsManager presented in third post.
The BaseForm has the icon displayed at the left upper corner and a property Key used to store the key of the form used by FormsManager. All forms derive from it and FormsManager accepts to open only forms assignable from that type.
Each view form has a menu which is not visible but when such form comes active it is automatically added to the main menu of the MDI container. If you download the source code You may be notice that MDI child forms menu is placed at the second position. To configure this one should keep MergeAction and MergeIndex of the MDI container’s menu with default values. But for the MDI child forms one should set MergeAction to Insert and set MergeIndex to 1.
Every menu operation has assigned shortcut key in order to be easy accessible. It is very useful and it is a normal practice when WinFomrs application is developed. It can be done very easy just go to the menu item properties and under Misc category set its ShortcutKeys and ShowShortcutKeys properties the way you preferred.
Below is the look of the application. To have a better look one can add nice icons to the buttons and menus.
And that is the end I didn’t post any code here! Feel free to download and do whatever with it if you found it useful!


October 27th, 2010 at 4:46 am
Hi Anton,
I just came upon your MDI example and have successfully attached the database and compiled after setting references for a couple of CrystalReports items.
I will be taking some time to learn MDI that you have shared and have run into two issues.
The first is minor … no images in the /images folder.
The second, more critical and my lack of knowlege of MDI may be the problem, but when I run the application and select any of the three buttons on the MDI screen: Car Details, Maintenance Report, or Fleet Spot Checks…all the same error: “Instance Error”.
Maybe you can help?
Thank you sir.
October 27th, 2010 at 12:20 pm
Hi Peg,
It is an old post and it will help me if you can tell me the full error message?
-Anton
October 27th, 2010 at 6:27 pm
I couldn’t figure out how to capture the whole message. Can I email you the JPG?
October 27th, 2010 at 9:59 pm
You cannot but you can send me an e-mail as you did. I got the image. You also can copy the text of a modal window using CTRL+Ins.
It looks like the database instance is not accessible for the application. It can be a wrong sql server name or configuration of the SQL Server instance ports and protocols. Can you tell me the sql connection string that you use?