[ Pobierz całość w formacie PDF ]
.Figure 4.16shows the IDE after performing the last exercise.FIGURE 4.16.Fourtool windows docked to the Code Editor.No Docking, PleaseSometimes you don't want a particular window to be dockable.As nice as dockablewindows are, sometimes it's hard to find a location to place a window when you don'twant it docked.It seems like anywhere you try to put the window it wants to dockto something.The good news is that you can shut off the docking capability of anytool window.Each of the dockable tool windows has a menu item at the bottom of its contextmenu called Dockable.If Dockable is checked, the window is dockable.If Dockableis not checked, the window is not dockable and you can place it anywhere in the IDE.The dockable windows in the Delphi IDE are a great feature.You can arrange thetool windows you use most often in any way you want.You no longer have to go huntingfor a Project Manager, Watch List, or Object Inspector hidden under other windows.The window you are looking for is just a couple of mouse clicks away.An MDI Sample ProgramTo help solidify today's discussion of projects and forms, let's create an MDIapplication.This application will enable you to open and save graphics files suchas bitmaps, icons, and metafiles.In order to complete the task, you should havea master plan.Here's what you need to do:1.Create the main window form (an MDI parent), including a menu.2.Write code for the File | Open and File | Save menu selections.3.Write code for the Cascade, Tile, and Arrange All items on the Windowmenu.4.Create the MDI child forms.5.Create an About box.6.Stand back and admire your work.There's no point in dawdling (time is money!), so let's get right to it.Creating the Main Window FormFirst you'll create the main window form.The main window for an MDI applicationmust have the FormStyle property set to fsMDIForm.You also need to add a menu tothe application, as well as File Open and File Save dialog boxes.Follow these steps:1.Start Delphi and choose File | New Application from the main menu.2.For the main form, change the Name property to MainForm.3.Change the Caption property to Picture Viewer.4.Change the Height to 450 and the Width to 575 (or other suitable valuesfor your display resolution).5.Change the FormStyle to fsMDIForm.Okay, now you've got the main part of the form done.Next you'll add a menu tothe form.Because I haven't discussed the Menu Designer yet, you will take the easyroute to creating a menu.To do that, you can take advantage of a Delphi featurethat enables you to import a predefined menu, as follows:1.Click the Standard tab of the Component palette and click the MainMenubutton.2.Click on the form to place a MainMenu component on the form.It doesn'tmatter where you place the component because the icon representing the menu is justa placeholder and won't show on the form at runtime.This is how nonvisual com-ponentsappear on a form.3.Change the Name property to MainMenu.4.Double-click the MainMenu component.The Menu Designer is displayed.(You'll read about the Menu Designer in more detail on Day 6.)5.Place your cursor over the Menu Designer and click your right mousebutton.Choose Insert from Template from the context menu.The Insert Template dialogbox appears.Figure 4.17 shows the Insert Template dialog box with the Menu Designerbehind it.FIGURE 4.17.TheMenu Designer with the Insert Template dialog box open.6.Choose MDI Frame Menu and click OK.The menu is displayed in the MenuDesigner.7.Click the system close box on the Menu Designer to close it.Now you should be back to the main form.Notice that you have a menu on the form.You can click on the top-level items to see the full menu.Don't click on any menusubitems at this point--you'll do that in a minute.Notice that there are a lot ofmenu items.You won't need all them, but for now you can just leave the extra itemswhere they are.Now you need to prepare the File Open and File Save dialog boxes:1.Click the Dialogs tab on the Component palette.Choose an OpenPictureDialogcomponent and place it on the form.The OpenPictureDialog component's icon can beplaced anywhere on the form.2.Change the Name property of the Open dialog box to OpenPictureDialog.3.Change the Title property to Open a Picture for Viewing.4.Add a SavePictureDialog component.5.Change the Name property of the component to SavePictureDialog andthe Title property to Save a Picture.Your form should now look like the one shown in Figure 4.18.FIGURE 4.18.Theform up to this point.Writing Code for the File | Open and File | Save As MenuItemsNow you are ready to write the code to implement the File | Open and File | SaveAs menu items
[ Pobierz całość w formacie PDF ]