Home | Articles | Links | Contact
 
Title Tile, cascade, arrange and list mdi child windows
Description Once you have your mdi framework up and running it's time to improve it with some common and very easy options for arranging the child forms inside the main window
Date 10/22/2000
Last revision
Related articles

Basic MDI ( Multiple Document Interface) programming with Delphi 5
ActiveMDIChild versus merging the main form menu and the child window menus in a mdi application

 

If you have read the previous article called "Basic MDI ( Multiple Document Interface) programming with Delphi 5" or you have some basic knowledge on mdi applications with Delphi, you already know how to define parent and child windows and create them dynamically at execution time. However, there's a long way to go before we can say that we have done a good job with mdi.

The next thing we can do to improve our sample application we started in the previous article is to create a window menu. The window menu should have the options that the users need to organize the child windows inside the main window. Normally, there's also a list at the bottom of the window menu showing the captions of all the child windows that are contained in the main form. Open the main form of your mdi application and double click on the main menu component you should have, if you don't have any, just create one by selecting the TMainMenu component in the component palette and clicking on the form. In the menu designer add one more option to the menu bar and give it the caption "&Window". The default name for the new option will be window1. Let's keep this name. Below the window caption and inside its menu, add some new items with captions "&Cascade", "&Horizontal tile ", "&Vertical tile", "&Arrange icons".

You can now close the menu designer and click on the main form to get its properties in the Object Inspector. Look for a property called "WindowMenu" and select window1. This setting tells the main form to use the menu item window1 to show the list of mdi child windows.

Let's add some code for arranging windows. Select the main form, you will see at the top of the window the main menu we have prepared for the form. In Delphi, if you select an option of a main menu at design time, you will be presented the code window ready for entering the event handler for the OnClick event of the menu option you selected. Select Window then Cascade, in the code window type just one word that will become the event handler for that option:

procedure TForm1.Cascade1Click( Sender: TObject);
begin
  Cascade
end;

As you can guess, the "cascade" method of the TForm class and its descendants organizes in cascade the child windows of the form we are sending the call to. After such a big effort, you can do the same for the rest of the options in the window menu.

procedure TForm1.Horizontaltile1Click( Sender: TObject);
begin
  TileMode := tbHorizontal;
  Tile
end;
procedure TForm1.Verticaltile1Click( Sender: TObject);
begin
  TileMode := tbVertical;
  Tile
end;
procedure TForm1.Arrangeicons1Click( Sender: TObject);
begin
  ArrangeIcons
end;

The "tile" method organizes the child windows by filling all the available space in the parent window. There're two differents modes for tile: tbHorizontal and tbVertical. He have to set the proper value in the "TileMode" property before we issue the call to "Tile". There's no need to explain these two modes, just try them. The last one is also self-explanatory, if you minimize the child windows in your application and then you want to organize them, give this option a chance.


Was this article useful for you?
Yes No
Any other comments will be welcome

 

Home | Articles | Links | Contact