ActiveReports 10
Stylesheets
ActiveReports 10 > ActiveReports User Guide > Samples and Walkthroughs > Samples > Section Report > Layout > Stylesheets

This sample demonstrates how you can change styles at run time to provide a different look to a same report. The project includes two reports, three reportstyles and a form containing the ActiveReports Viewer control and other controls that allow you to select any combination of styles and reports.

Sample Location

Visual Basic.NET

<User Folder>\Documents\GrapeCity Samples\ActiveReports 10\Section Reports\Layout\Stylesheets\VB.NET

C#

<User Folder>\Documents\GrapeCity Samples\ActiveReports 10\Section Reports\Layout\Stylesheets\C#

Runtime Features

Choose Report
Choose between the type of report, Categories and Product List, you want to display in the Viewer control.

Choose Style
Choose between Classic, Colored and External style sheet options to apply the style to the selected report.
Clicking the Choose button option for External style sheet displays the Open dialog that shows only *.reportstyle files, and passes the selected reportstyle path and file name string to the externalStyleSheet variable.

Run Report button
Click this button to display the selected report with the applied style in a Viewer control. Clicking this button creates an SectionReport object, assigns the selected report to it, and assigns a path and file name string to the styleSheet variable. It then assigns the style sheet to the report using the LoadStyles(styleSheet) method, runs the report, and displays it in the viewer.

Project Details

Report Style Sheets

Look in Solution Explorer to see several *.reportstyle files. These are XML-based files that hold styles that you can apply to TextBox, Label, CheckBox, and ReportInfo controls on ActiveReports. Double-click one to open it. Each reportstyle contains a set of values for each of the standard style names:

  • Normal
  • Heading1
  • Heading2
  • Heading3
  • DetailRecord
  • ReportTitle

When you select one of these style names on a report control, ActiveReports retrieves the style values, such as font size and color, from the specified style sheet when it runs the report.

For more information on creating your own style sheets, see Use External Style Sheets.

Reports

Two reports, CategoryReport and ProductsReport, are included in this sample so that you can apply styles in different ways. Open one of the reports, and select the TextBox and Label controls on it to see which style is used for each.

StyleSheetsForm

The form in this project features radio buttons for choosing the report and style you want, a Choose button that opens a standard Windows Open dialog where you can select a reportstyle, and a Run report button that runs the selected report, applies the selected reportstyle, and displays the results in the ActiveReports viewer control below.

To see how all of this works, right-click the form and select View Code.

Choose Button Click Event

This event contains code that sets up an Open dialog that shows only *.reportstyle files, and passes the selected reportstyle path and file name string to the externalStyleSheet variable.

Run Report Button Click Event

This event contains code that creates an empty SectionReport object, assigns the selected report to it, and assigns a path and file name string to the styleSheet variable. It then assigns the style sheet to the report using the LoadStyles(styleSheet) method, runs the report, and displays it in the viewer.

See Also

How To