341 346




Visual Basic 6 Black Book:Windows Common Dialogs
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Chapter 11Windows Common Dialogs


If you need an immediate solution to:
Creating And Displaying A Windows Common Dialog
Setting A Common Dialog’s Title
Did The User Click OK Or Cancel?
Using A Color Dialog Box
Setting Color Dialog Flags
Using The Open And Save As Dialogs
Setting Open And Save As Flags
Getting The File Name In Open, Save As Dialogs
Setting Maximum File Name Size In Open And Save As Dialog Boxes
Setting Default File Extensions
Set Or Get The Initial Directory
Setting File Types (Filters) In Open, Save As Dialogs
Using A Font Dialog Box
Setting Font Dialog Flags
Setting Max And Min Font Sizes
Using The Print Dialog Box
Setting Print Dialog Flags
Setting The Minimum And Maximum Pages To Print
Setting Page Orientation
Showing Windows Help From A Visual Basic Program

In Depth
In this chapter, we’re going to examine the Windows Common Dialogs, which provide a powerful and professional set of dialog boxes for interacting with the user. Microsoft created the Common Dialogs to promote a common user interface across all Windows programs, and in fact the Common Dialogs do work well—and they make programming easier for the programmer. Having a common user interface across all Windows programs is valuable for the user, because it simplifies tasks. For the programmer, the Common Dialogs means that we have a powerful set of dialog boxes ready for us to use, without having to create them ourselves. From both ends of the spectrum, then, the Windows Common Dialogs may be considered a success.

The Common Dialog control can display five different dialog boxes—Open A File, Save A File, Set A Color, Set A Font, and Print A Document.
The Common Dialog Control
The Common Dialogs are all part of one control: the Common Dialog control. You add that control to a program with the Visual Basic Project|Components menu item. Click the Controls tab in the Components box that opens, and select the entry labeled Microsoft Common Dialog Control, then click on OK to close the Components box. You add a Common Dialog control to a form in the usual way—just double-click the Common Dialog tool in the toolbox, or select it and paint the control on the form. The Common Dialog tool appears as the eleventh tool down on the right in the Visual Basic toolbox in Figure 11.1. The Common Dialog control will appear as a nonresizable icon on your form and is not visible at runtime.


Figure 11.1  The Common Dialog tool.
You use the control’s Action property to display a dialog box or, equivalently, these methods:

•  ShowOpen—Show Open dialog box
•  ShowSave—Show Save As dialog box
•  ShowColor—Show Color dialog box
•  ShowFont—Show Font dialog box
•  ShowPrinter—Show Print or Print Options dialog box

Besides these dialog boxes, you can also display Windows Help:


•  ShowHelp—Invokes the Windows Help engine

The Common Dialog control automatically provides context-sensitive Help on the interface of the dialog boxes. You invoke context-sensitive Help by clicking the Help button labeled What’s This in the title bar, then clicking the item for which you want more information. In addition, you can right-click the item for which you want more information, then select the What’s This command in the displayed context menu.


TIP:  We might also note, by the way, that there is no way currently to specify where a dialog box is displayed; that might change in some future release.

As an example, the Font dialog box appears in Figure 11.2.


Figure 11.2  The Font dialog box.
That’s really all the overview we need. We’re ready to start the Immediate Solutions now.

Immediate Solutions
Creating And Displaying A Windows Common Dialog
The Testing Department is calling again. Your program, SuperDuperTextPro, is great, but why is the File Save As dialog box the size of a postage stamp? And why is it colored purple? Shouldn’t it match the uniform kind of dialog box that other Windows programs use?
To make your dialog boxes look just like the dialog boxes other programs use (and add professionalism to your program), you can use the Windows Common Dialogs, which are wrapped up in the Windows Common Dialog control. The Common Dialog control can display five different dialog boxes—Open A File, Save A File, Set A Color, Set A Font, and Print A Document, and you can also display Windows Help.
Adding a Windows Common Dialog control to your program is easy: just follow these steps:

1.  Select the Project|Components menu item.
2.  Select the Controls tab in the Components box that opens.
3.  Select the entry labeled Microsoft Common Dialog Control, then click on OK to close the Components box.
4.  Add a Common Dialog control to a form in the usual way—just double-click the Common Dialog tool in the toolbox, or select it and paint the control on the form. (The Common Dialog tool appears as the eleventh tool down on the right in the Visual Basic toolbox in Figure 11.1.)
5.  Add the code you want to open the dialog box and make use of values the user sets.

To display various dialog boxes, you use these Common Dialog methods (for example, CommonDialog1.ShowColor):

•  ShowOpen—Show Open dialog box
•  ShowSave—Show Save As dialog box
•  ShowColor—Show Color dialog box
•  ShowFont—Show Font dialog box
•  ShowPrinter—Show Print or Print Options dialog box
•  ShowHelp—Invokes the Windows Help engine

You can also set the Common Dialog’s Action property to do the same thing (and in fact, that’s the way you used to display Common Dialogs until recent Visual Basic releases). Microsoft says that using the preceding methods “adds functionality,” but in fact, the two ways of displaying dialog boxes are equivalent at this writing (although using methods like ShowHelp instead of Action = 6 makes code a little clearer). Here are the values you can place in the Action property:

•  0—No action
•  1—Displays the Open dialog box
•  2—Displays the Save As dialog box
•  3—Displays the Color dialog box
•  4—Displays the Font dialog box
•  5—Displays the Print dialog box
•  6—Runs winhelp32.exe





Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
demo cgi 341
338 341 2kik7bqsuvg6pw2lts4uqae265zwjmklsp6fk5y
16 (346)
README (346)
20 Diagnozowanie i naprawa układów hydraulicznychid!341
SIGMUND EMRING (RINGECK) 1508 E 1939 65 341
341 344
341 (2)
05 (341)
341 345 ngtcyhsfuohpuoerl2lmbzij7fsdqlbw67zeyxq
341,17,artykul

więcej podobnych podstron