The Main Form

I mentioned in the previous article that we need an entry screen, but it won’t contain much because I haven’t designed it yet. It is time to build something, but nothing very fancy.

I will go through this in detail because it is the same procedure that I will adopt for all my forms, with a few exceptions.

In Solution Explorer I right clicked on the name of my project, which in this case is HourWin, and in the pop-up menu selected Add inherited form. In the Add New Item dialog box I gave the form the name MainForm and clicked OK. A new dialog appeared asking me which form I wanted to inherit from. I clicked BaseForm and OK. A new form was created.

I could have merely added a new form, and in the code changed the inherits to BaseForm.

For this time only, I have to change the Project Properties so that the new MainForm is the start up form.

I now have a form which shows me two red lines running down each side of the form, and 25 pixels from the border. I will use these as guides to place my controls. The code entered into the paint method in the BaseForm ensures that these only appear if the form is in Design mode.

So now I need some menu items. I will follow the normal Windows standard and have the first menu item File, and under that I will place Exit. I also know that the first Form I am going to build is for my Contact subsystem, so I may as well create a menu item to access that form.

I build these menu items using the menu control from the toolbox. The File menu item will not have any code attached so I will leave it with its default name. The Exit item will have code so I will change its name to mnuExit, and in the code view simply tell it to end. At some stage I might want to add other code to perform clean up operations, but I am not sure yet. At this stage all this window does is provide me with an entry point to the application sub-systems.

I haven’t worked out the design of this form yet, so to get to the Contacts section I will add another main menu item, Contacts, and under that an item Details with the name mnuContactDetails. This gives me the option of adding more windows which relate to Contacts at a later stage, if I want them.

The final thing to do is show the name of the application in the Main Form. In the code after InitializeComponent I added Me.Text = MyName. MyName can be set in one of two places. In an application configuration file or in a module. It doesn’t really matter which. The point is that it only has to be set once. I set it to Midnight Hour 1.0, and now we are done. We have a form that does nothing except exit the application.