Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
81
Добавлен:
11.05.2015
Размер:
2.11 Mб
Скачать

NOTE: If you close the Create Report Expert before clicking Finish, the Report Designer Component will assume that you wish to use an Empty Report. However, the data source you selected will be available. You will also be prompted to add the Smart Viewer control to your project.

Adding the Smart Viewer

After you have finished designing your report in the Create Report Expert, you have the option of automatically adding the Smart Viewer Component to your Visual Basic project. The Smart Viewer displays your report at runtime and allows a user to navigate through the report. When you add the Smart Viewer, a new Form is added to your project, and the Smart Viewer is added to the form as an object.

When you click Finish in the Create Report Expert, the Crystal Report Expert dialog box appears.

1The first option is whether or not you want a form containing the Crystal Reports Smart Viewer added to your project. The Smart Viewer is an ActiveX control that allows you to display reports directly in a form inside your application. Click Yes, if this option is not already selected.

2The second option is whether or not the form containing the Smart Viewer should be the first form displayed when your application runs, the startup form. Click Yes for this option as well.

You could design your application so that another form is displayed initially, and the Smart Viewer form is displayed in response to some event. However, for the purposes of this demonstration, your application will simply display the report immediately upon running.

3Click OK in the Crystal Report Expert dialog box. If you look in the Project window for your Visual Basic project, you will see that a new form and the Report Designer Component ActiveX designer have been added. In addition, the Report Designer Component design window appears in the Visual Basic IDE.

4Save your new project and the attached forms. For this tutorial, you can use the name CrystalReport1 for your project.

Running the Application

Your Report Designer Component project is complete. Now, you can run the application within Visual Basic to see the results.

1Click the Start button on the Visual Basic toolbar, or select the Start command from the Run menu. The Report Designer Component connects to your data source through ADO, and generates a report based on the design you created. The report is displayed inside the Crystal Smart Viewer, which sits on a Visual Basic form object.

2Use the arrow buttons at the top of the Smart Viewer to page through the report.

3If your system is connected to a printer, click the Print Report button to print a hard copy.

4Click CA in the tree control at the left side of the Smart Viewer. The group containing California data appears in the Smart Viewer.

5Click the plus sign next to CA to expand the CA group in the tree control. Four cities are listed for California.

The Report Designer Component

155

6Click San Diego in the CA group. Data for San Diego is highlighted in the Smart Viewer window.

7Select Vancouver from the drop-down list next to the Search Text button.

NOTE: If you are unsure of the name of a toolbar button, hold the mouse pointer over the button for a couple of seconds, and a tool tip will appear that indicates the button’s name.

8Click the Search Text button. Data for Vancouver is highlighted in the Smart Viewer.

9When you are finished reviewing the report in the Smart Viewer window, close the window. Your application stops running as well.

Part Two

CrystalReport1 - The Report Designer Component

The Report Designer Component is an ActiveX Designer, and an instance of the designer has been added to the Designers section of your project. The default name for the designer is CrystalReport1. Since ActiveX designers are, by definition, visual interfaces that simplify an application design task, the CrystalReport1 designer also appears inside the Visual Basic IDE.

The CrystalReport1 designer provides a simple, yet powerful environment for controlling how text and data appear inside your report. The design environment allows simple changes to text font and color, but also allows complex manipulation of data such as custom grouping. Furthermore, the design environment has been completely integrated with Visual Basic.

1Select the CrystalReport1 designer in the Project window, and click the View Code button in the Project window's toolbar. A code page appears for the CrystalReport1 designer.

2In the drop-down list at the upper left of the Code page, notice that the entire report, along with each section within the report, is represented by a separate object.

3Select one of the Section objects in the code page. You will see that Section objects have Format events. Code written for a Format event will be executed when that particular section is formatted and displayed inside the Smart Viewer.

4Close the Code page for the CrystalReport1 designer.

CRViewer1 - The Smart Viewer Control

The Smart Viewer is a standard ActiveX control that can be added to any ActiveX container. In Visual Basic, a form is the most commonly used container. When you finished designing your report in the Create Report Expert, the Crystal Report Expert dialog box allowed you to automatically add a new form to your project containing the Smart Viewer control.

The Smart Viewer is the window within which your report is actually displayed. It provides a standard set of controls and features that allow you to interact with the report, moving through pages, drilling-down on groups, and even printing the report. A report can be printed or exported to a different file format without the use of the Smart Viewer, but if you want your users to be able to review the report on screen, you will need to include the Smart Viewer in your project.

1Choose the COMPONENTS command from the Project menu. The Components dialog box appears.

The Report Designer Component

156

2Scroll through the list of available components on the Controls Tab of the dialog box. Notice that the Crystal Report Smart Viewer control is toggled on.

3Click OK, and the Components dialog box closes.

4If the Visual Basic Toolbox is not available, select the Toolbox command from the View menu. Notice that a new control appears at the bottom of the Toolbox.

5Move the mouse pointer over the new control in the Toolbox, and hold it still for a couple of seconds. A Tool Tip appears with the name of the new control: CRViewer.

6In the Project window, select the form containing the Smart Viewer control. If you followed the tutorial exactly, this will be Form2.

7Click the View Object button in the toolbar for the Project window. Form2 is displayed with the Smart Viewer control. Notice that, at design time, the Smart Viewer control contains several of the basic controls used when you viewed the report at runtime. The Smart Viewer is also resizable inside the form.

NOTE: When you view the form containing the Smart Viewer control, the control may appear to completely fill the form. However, the control is a separate object inside the form and can be resized within the form.

8In the Properties window, select the CRViewer1 control from the list of objects. Properties appear that are specific to the Smart Viewer control.

The Code

Now you have seen the two principal objects added to your project, the Report Designer Component and the Smart Viewer control. The Report Designer Component provides an environment for designing powerful reports. The Smart Viewer control allows these reports to be displayed at runtime. There is only one element missing from the equation. You must have code that displays the Report Designer's report inside the Smart Viewer.

1With the form containing the Smart Viewer control active, select the Code command from the View menu. A code page for the form appears. There are three sections to the code that appears in the form, a General Declarations section, a Load event for the Form, and a Resize event for the Form.

2Examine the code in the General Declarations section:

Dim Report As New CrystalReport1

An instance of the CrystalReport1 object is declared. This object will be used in the Load event of the Form.

3Now, examine the code for the Load event of the Form:

CRViewer1.ReportSource = Report CRViewer1.ViewReport

The first line assigns the declared CrystalReport1 object to the ReportSource property of the Smart Viewer control, CRViewer1. For the Smart Viewer to display a report, it must know where to find that report. In this case, it gets the report from the Report Designer Component, CrystalReport1.

The second line of code simply tells the Smart Viewer to display the report. That is all of the code that is required.

The Report Designer Component

157

Соседние файлы в папке crystal