Search In Site

27 June, 2013

Window Common Dialog Boxes In Visual Basic

Creating And Displaying A windows Common Dialog
 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.
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

Now that you've added a Common Dialog control to your program, refer to the individual topics in this chapter for the dialog box you want to work with to see how to retrieve values from the user. TIP: Before displaying the Font and Help dialog boxes, you need to set the Common Dialogs control's Flags property or nothing will appear.

Setting A Common Dialog's Title
The Aesthetic Design Department is calling again: can_t you change the text in the title bar of those dialog boxes? How about changing the title of the Open dialog box from Open to Select A File To Open?
Although some programmers may question the wisdom of changing a Common Dialog's title, you can do it using the DialogTitle property. As an example, here we're changing the title of an Open dialog box to Select a file to open.

Private Sub Command1_Click()
CommonDialog1.DialogTitle = "Select a file to open"
CommonDialog1.ShowOpen
End Sub


WARNING! Note that this property, DialogTitle, does not work for the Color, Font, and Print dialog boxes.

0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget