| Hyderabad Jobs | Book Website | ![]() |
I Love Hyderabad | Hyderabad Colleges |
| Home | Business Emails | Hyderabad Classifieds | Contact Us | |
| 7 Wonders of Hyderabad | Web Hosting | Yellow Pages | Our Network | |
Mastering PowerBuilder
Print Preview - Zoom UtilityWe've already added some code to implement the Print Preview function, but as you will remember, it wasn't very useful - all it did was format the object ready for printing; no other functionality was provided. We can improve on this by allowing the user to zoom in or out on the object when they Print Preview. As our user interface is now becoming much more graphic based, let's use a scrollbar to implement this extra feature. Paint a child window as shown in the following picture. Disabling the control menu, the resize, maximize and minimize buttons. At the top of the window we have two StaticText controls with 40% and 200% as the text. The control below the StaticText controls is a Horizontal Scrollbar, leave its name to the default. The rest are two CommandButtons, cb_print and cb_close. Save this window as w_print_preview_zoom.
Declare an instance variable called iDw of type DataWindow.
Write the following code to the window's open event.
The comments in the code explain exactly what this does. The final line turns on the rulers for print preview. There are five specific events associated with a scrollbar, as depicted in the following table. These events are executed depending on what the user does or where he clicks.
The code for each of these is fairly simple. First, the LineLeft event:
We decrease the current position of the scrollbar by one unit and use Modify() to alter the print preview zoom value. Note that the above script is making sure that the zoom value doesn't exceed the minimum value.
The code for the PageLeft event is exactly the same, except that we move the current position by five units, as opposed to one:
The amount by which you move the current position is entirely optional. The scripts for LineRight and PageRight are exactly the same, except that they increase the current position by five and check that we don't go over the maximum value.
The code for the Moved event is slightly different, but simpler than its cousins:
This code simply sets the print preview zoom property to the value of the current position of the scrollbar. Finally, we want to actually be able to print the DataWindow once we've previewed it, so we add the following code to the Print button:
When the user close this window, we need to set the DataWindow back to normal, i.e., not in print preview mode. Write the following code to the clicked event of cb_close CommandButton.
Want to see this in action? If you already don't have, add a menu item "Print Preview Zoom" just above the "Print Preview" under the "File" menu bar option in the m_sheet_menu menu. Write the code to trigger the ue_print_preview_zoom event in the active window. Declare ue_print_preview_zoom user-defined event and write the following code:
Run the application and test it. Working? Use it in your real applications. You pay No Royalties. But, you need to help us with a small thing. Right now, 40% and 200% is hard coded in the code. Make changes to set these values any number the user-developer of this utility wants. That's your exercise.
|
| Copyright © 1996 - 2006 HamaraShehar.com Pvt. Ltd. All Rights Reserved.
Domain Registration, Website Design, Website Hosting by HamaraShehar.com |