The use of CommonDialog control in VB (II.)

Source: Internet
Author: User
Tags exit goto include microsoft sql server odbc

Using the Print dialog box
The Print dialog box allows the user to specify a method for printing output. Users can specify the range of pages to print, print quality, number of copies, and so on. This dialog box also displays information about the currently installed printer and allows the user to configure or reinstall the new default printer.
Note that this dialog box does not really send data to the printer. It allows the user to specify how data is printed. You must write code implementations to print the data in the selected format.
For more information about printing data, see Chapter 12th, "Working with text and graphics." At run time, when the user makes a selection in the Print dialog box, the following properties will contain information about the user's options.

To display the Print dialog box
1. Set the desired default setting value for the dialog box by setting the appropriate Print dialog box properties. For example, to display 2 in the number of Copies box when a dialog box is displayed, set the Copies property to 2:
Commondialog1.copies = 2
2. Displays the Print dialog box by using the Showprinter method.
When the user clicks the COMMAND1 command button, the following code displays the Print dialog box:
Private Sub Command1_Click ()
Dim beginpage, EndPage, Numcopies, Orientation. I
' sets Cancel to True.
Commondialog1.cancelerror = True
on the Error GoTo errhandler
' Displays the Print dialog box.
Commondialog1.showprinter
Gets the user selected value from the dialog box.   
beginpage= commondialog1.frompage
EndPage = commondialog1.topage
numcopies= commondialog1.copies
Orientation=commondialog1.orientation
For i = 1 to numcopies
' places code here to send data to the printer.
Next
Nxit Sub
ErrHandler:
The user presses the Cancel button.
Exit Sub
End Sub
Note If you set the Printerdefault property to True, you can print on the Visual Basic printer object. In addition, when the Printerdefault property is true, all changes made in the settings section of the Print dialog box will change the printer setting values in the user's printer settings.

To display a Help file using the ShowHelp method
You can display Help files using the showhelp method of the CommonDialog control.
To display a Help file using the ShowHelp method
1. Set the Helpcommand and HelpFile properties.
2. Displays the specified help file using the ShowHelp method.
When you click the Command1 command button, the following code displays the specified help file:
Private Sub Command1_Click ()
' Set Cancel to True.
Commondialog1.cancelerror = True
On Error GoTo ErrHandler
' Set the Helpcommand property
Commondialog1.helpcommand = Cdlhelpforcefile
' Specifies the help file.
Commondialog1.helpfile = "C:\Windows\Cardfile.hlp"
' Show the Windows help engine.
Commondialog1.showhelp
Exit Sub
ErrHandler:
' The user presses the Cancel button.
Exit Sub
End Sub
For more information about displaying Help files for common dialog box controls, see the VisualBasic 6.0 Language Reference manual, Helpcommand properties, HelpFile properties, and ShowHelp methods.

Using the Data Control

The internal data control uses Microsoft's Jet database engine to achieve access to the same database engine that Microsoft Access uses. This technology gives users seamless access to many standard database formats, and allows users to create data-recognition applications without writing any code. This intrinsic data control is best for smaller (desktop) databases, such as Access and ISAM databases. The
can use this intrinsic data control to create an application to display, edit, and update information from a variety of existing databases. These databases include Microsoft Access, Btrieve, DBASE, Microsoft FoxPro, and Paradox. You can also use this control to access Microsoft Excel, Lotus 1-2-3, and standard ASCII text files just as you would access a real database. In addition, the data control can access and manipulate remote Open Database connectivity (ODBC) databases, such as Microsoft SQL Server and Oracle.
Note that both the data control and the remote Data control are contained in Visual Basic to provide backward compatibility. However, because ActiveX Data Objects (ADO) are more adaptable, it is recommended that you use the ADO data control to create a new database application. For more information, see "Using the ADO Data control." The
Data control, Remote Data Control, and ADO data controls are conceptually similar: all three connect a data source to a data-bound control. All three share the same appearance--a total of four buttons that allow users to directly reach the beginning of the recordset, the end of the recordset, and scroll forward or backward in the recordset.

Create a simple database application using the data control
to use the data control to create a simple database application
1. Place a data control on a form. The data control is an intrinsic control and is therefore always available.
2. Click and select the Data control and press F4 to display the Properties window.
3. In the Properties window, set the Connection property to the type of database you want to use.
4. In the Properties window, set the DatabaseName property to the file or directory name of the database you want to connect to.
5. In the Properties window, set the record Source property to the name of the database table you want to access.
6. Place a text box control on the form.
7. Click and select the TextBox control and set the data Source property in its Properties window to that of this data control.
8. In this Properties window, set the Data field property to the name of the field that you want to view or modify in the database.
9. Repeat the 6th, 7, 8 steps for each of the other fields you want to access.
10. Press the F5 key to run the application.

Set data-control-related properties
The following data-related properties can be set at design time. This list gives a logical order for setting these properties:
Note that database technology is a complex science, and the following recommendations do not mean to be used as rules.
1. The Recordsettype-recordsettype property determines whether the recordset is a table, a dynamic set (dynaset), or a snapshot. This selection will affect which Recordset properties are available. For example, a snapshot-type Recordset has more restrictions than a dynaset record set.
2. The Defaulttype-defaulttype property specifies whether to use the JET workspace or the ODBCDirect workspace.
3. The Defaultcursortype-defaultcursortype property determines the position of the cursor. You can use an ODBC driver to determine the location of the cursor, or to specify a server or ODBC cursor. The Defaultcursortype property is valid only if the ODBCDirect workspace is used.
4. exclusive-determines whether the data is for single-user or multiuser environments.
5. Options-This property determines the characteristics of the recordset. For example, in a multiuser environment, you can set the Options property to prevent changes made by others.
6. BOFAction, eofaction-These two properties determine the behavior when the control is at the beginning or end of the cursor. Possible choices include staying at the beginning or end, moving to the first or last record, or adding a new record (only at the end).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.