53
366
Creating Charts
In the initial versions of C1Report, adding charts to reports required handling the StartSection event, generating
the chart, and assigning the chart image to a field's Picture property. This is not hard to do, and continues to be the
most flexible way to add dynamic images to reports.
However, this approach has two drawbacks:
It requires you to write code outside the report definition, which means only your application will be
capable of showing the report the way it is meant to be shown.
It requires you to write code for generating the chart, which can be tedious.
The current C1Report supports custom report fields, including a chart field that is based on the C1Chart control.
To add a chart field to a Group Header section in your report, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In the Fields group of the Design tab, click the Add Chart Field button
.
5.
Click in the Group Header section of your report and drag the field to resize the chart.
6.
From the Properties window, set the chart field's Chart.DataX and Chart.DataY properties to the values
you want to display on the chart. You can show several series by setting the Chart.DataY property to a
list of fields delimited by semicolons (for example, "UnitsInStock;ReorderLevel").
The chart data is automatically scoped to the current report group. For example, when rendering the "Beverages"
section, only data for that category will be charted. You can customize the chart using many other properties such
as Chart.ChartType, Chart.GridLines, Chart.Use3D, and Chart.Palette properties.
For more information on creating chart fields, see the Adding Chart Fields topic.
Sample Report Available
For the complete report, see report "11: Charts" in the CommonTasks.xml report definition file, which is
available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Creating Custom Fields
You can create your own custom fields and add them to the Report Designer palette. To do that, you have to:
1.
Create a custom field class that derives from C1.Win.C1Report.Field.
2.
Register your custom field assembly in the Report Designer's settings file.
This is how the Chart and Gradient fields are implemented. The source code for these custom fields is available;
you can use it as a starting point to create your own custom fields. The Chart and Gradient fields are registered in
the C1ReportDesigner settings file with this entry:
<customfields>
<item
value="C1.Win.C1Report.CustomFields;C1.Win.C1Report.CustomFields.Chart" />
<item
value="C1.Win.C1Report.CustomFields;C1.Win.C1Report.CustomFields.Gradient"
/>
</customfields>
51
367
For example, to add a new field to the Designer palette, add your control to the <customfields> section in the
"C1ReportDesigner.2.exe.settings" file:
<customfields>
<item
value="C1.Win.C1Report.CustomFields.2;C1.Win.C1Report.CustomFields.Chart"
/>
<item
value="C1.Win.C1Report.CustomFields.2;C1.Win.C1Report.CustomFields.Gradien
t" />
<!-- THIS LINE WILL ADD A NEW FIELD TO THE DESIGNER -->
<item value="MyCustomFieldAssembly;MyCustomFieldAssembly.MyField" />
</customfields>
This assumes that your field is called "MyField" and it can be found in the assembly called
"MyCustomFieldAssembly"
Sample Report Available
For the complete report, see report "12: Custom Fields" in the CommonTasks.xml report definition file, which is
available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Customizing the Page Headers
This section explains how to customize the behavior of page headers.
Adding a Continued Label to Headers on Page Breaks
Group Header sections are repeated across page breaks if their Repeat property is set to True. This makes the
report easier to read, but it can be hard to tell if a group header on a page marks the beginning of a group or is just
a continuation.
One way to address this is to add a field with a "Continued" label named, fContinued, for example to the group
header and control its visibility with script. To do this, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select Detail from the drop-down list above the Properties window.
5.
Locate the Detail.OnPrint property and click the empty field next to it, and then click the ellipsis button.
6.
The VBScript Editor appears. Enter the following VBScript expression in the code editor:
' VBScript: Detail.OnPrint
fContinued.Visible = true
7.
Then select GroupFooter from the drop-down list above the Properties window.
8.
Locate the GroupFooter.OnPrint property and click the empty field next to it, and then click the ellipsis
button.
9.
The VBScript Editor appears. Enter the following VBScript expression in the code editor:
' VBScript: GroupFooter.OnPrint
fContinued.Visible = false
45
368
If the fContinued field is initially invisible, then the script will show the label only on continued page headers. This
script ensures that the fContinued field is visible within the group. Any page breaks created after the group footer
and before the next Detail section will not show the label.
Sample Report Available
For the complete report, see report "18: Continued Headers" in the CommonTasks.xml report definition file,
which is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Changing Page Headers Dynamically
To specify whether Page Header and Page Footer sections should appear on all pages, or be suppressed on the
pages that contain the report Header and report Footer sections use C1Report's PageHeader and PageFooter
properties.
Sometimes you may want to further customize this behavior. For example, you may want to render different
headers on odd and even pages. This can be done with some script that shows or hides fields depending on the
page being rendered. To do this, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select Detail from the drop-down list above the Properties window.
5.
Locate the OnFormat property and click the empty field next to it, and then click the ellipsis button.
6.
The VBScript Editor appears. Enter the following VBScript expression in the code editor:
odd = (page mod 2 <> 0)
h1odd.Visible = odd
h2odd.Visible = odd
h1even.Visible = not odd
h2even.Visible = not odd
This script will show or hide fields for odd and even pages if a report header contains several fields named
"h<x>odd" and "h<x>even".
Note that to prevent the page header from showing blank spaces, all the fields should have the CanShrink
property set to True.
Sample Report Available
For the complete report, see report "09: Dynamic Page Header" in the CommonTasks.xml report definition file,
which is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Customizing the Page Layout
The following topics explain how you can customize the layout of your report.
Controlling Page Breaks
By default, C1Report fills each page until the bottom, inserts a page break, and continues rendering in the next
page. You can override this behavior using several properties:
Read PDF in Web Image Viewer| Online Tutorials Extract images from PDF documents; Add, reorder pages in PDF files; detailed information for reading and editing PDF in RasterEdge Web Document Viewer
move pages in pdf; pdf change page order
51
369
Group.KeepTogether: Determines whether Group Header sections are allowed to render on a page by
themselves, if they must be rendered with at least one Detail section, or if the entire group should be kept
together on a page.
Section.KeepTogether: Determines whether page breaks are allowed within sections. It has lower
precedence than Group.KeepTogether.
ForcePageBreak: Allows you to specify that page breaks should be inserted before, after, or before and
after the section.
Field.KeepTogether: Determines whether page breaks are allowed within fields. This allows long Text
fields to span multiple pages. It has lower precedence than Section.KeepTogether.
ForcePageBreak: Allows you to specify that page breaks should be inserted before, after, or before and
after the field.
Set these properties through the Properties grid of the C1ReportDesigner.
You can use script to change the properties while the report is being rendered. For example, to cause page breaks
after each 10 Detail sections, complete the following steps:
1.
Open the C1ReportDesigner application. For more information on how to access C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in C1ReportDesigner, you can
modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select Detail from the drop-down list above the Properties window.
5.
Locate the OnPrint property and click the empty field next to it, and then click the ellipsis button.
6.
The VBScript Editor appears. Enter the following VBScript expression in the code editor:
cnt = cnt + 1
detail.forcepagebreak = "none"
if cnt >= 10 then
cnt = 0
detail.forcepagebreak = "after"
endif
Sample Report Available
For the complete report, see report "07: Force Page Breaks" in the CommonTasks.xml report definition file,
which is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Creating CanGrow/CanShrink Fields
It is common for report fields to have content that may span multiple lines or collapse to no lines at all. In some
cases, you may want to allow these fields to grow or shrink to fit their content rather than clip the excess or leave
white spaces in the report.
To do this, in Design mode of the C1ReportDesigner set the Field object's CanGrow and CanShrink properties to
True.
Fields that grow push down the fields below them. Likewise, fields that can shrink push up the fields below them.
Below in this case means "strictly" below, as shown in the following diagram:
.NET Multipage TIFF SDK| Process Multipage TIFF Files upload to SharePoint and save to PDF documents. View, edit, insert, delete and mark up pages in multi Easily add, modify, reorder and delete TIFF tags; Perfectly
change pdf page order preview; how to change page order in pdf acrobat
31
370
Field 1 will push or pull fields 2 and 3 when it grows or shrinks. Field 4 will not be affected because it is not
directly below field 1. The shaded area in the diagram shows the region affected by field 1.
If you want field 4 to remain aligned with fields 2 and 3, add an extra field spanning the whole area above fields 2
and 3. The new field will be pushed down by field 1 and will in turn push fields 2, 3, and 4. The following diagram
shows this new layout:
Sample Report Available
For the complete report, see report "06: CanGrow CanShrink" in the CommonTasks.xml report definition file,
which is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Creating a Gutter Margin
Gutter margins are extra space added to the margins next to the binding. They make it easier to bind the pages into
folders, brochures, and so on.
To add a gutter margin to a report, you should increase the MarginLeft property on odd pages and use the default
value on even pages. This can be done with script. To add script that changes the margins based on the page being
rendered, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select Detail from the drop-down list above the Properties window.
5.
Locate the OnPrint property and click the empty field next to it, and then click the ellipsis button.
6.
The VBScript Editor appears. Enter the following VBScript expression in the code editor:
' VBScript: Report.OnOpen
gutter = report.layout.marginleft ' initialize variable
49
371
' VBScript: Report.OnPage
report.layout.marginleft = _
Iif(page mod 2 = 1, gutter, gutter - 1440)
Sample Report Available
For the complete report, see report "10: Gutter" in the CommonTasks.xml report definition file, which is
available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Defining and Using Global Constants
There is no special mechanism for defining and using global constants in a report, but you can add hidden fields to
the report and use their values as global parameters. To do this, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In the Fields group of the Design tab, click the Add Label button to add a field to your report.
5.
Click on your report where you want the field placed and drag to resize the field.
6.
Set the following properties for the field:
Field.Name = linesPerPage
Field.Text = 14
Field.Visible = False
7.
To control the number of detail lines per page, use script. Select Detail from the drop-down list above the
Properties window.
8.
Locate the OnPrint property and click the empty field next to it, and then click the ellipsis button.
The VBScript Editor appears.
9.
Enter the following VBScript expression in the code editor:
cnt = cnt + 1
detail.forcepagebreak = "none"
if cnt >= linesPerPage then
cnt = 0
detail.forcepagebreak = "after"
endif
Note that the value in the linesPerPage field can be set prior to rendering the report, by changing the
field's Text property.
Sample Report Available
For the complete report, see report "08: Global Constant" in the CommonTasks.xml report definition file, which
is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
49
372
Specifying Custom Paper Size
By default, C1Report creates reports using the default paper size on the default printer.
You can specify the paper size and orientation using the PaperSize and Orientation properties. However,
C1Report checks that the selected paper size is available on the current printer before rendering, and changes to the
default paper size if the selected setting is not available.
If you want to specify a certain paper size and use it regardless of the printers available, set the PaperSize property
to Custom, and set the CustomWidth and CustomHeight properties to the page dimensions (in twips).
To specify a custom paper size of 25" x 11" for your report using the C1ReportDesigner:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select your report from the drop-down list above the Properties window.
5.
Locate Layout and expand the property node to view all available properties.
6.
Set the Custom Height property to 25" or 25in.
Notice that the measurement is converted into twips automatically. The Property window display the
measurement in twips (36000).
7.
Set the Custom Width property to 11" or 11in.
The Property window displays the measurement in twips (15840).
8.
Set the PaperSize property to Custom.
To specify a custom paper size of 25" x 11" for your report using code:
Regardless of what is available on the printer, the following code sets the report paper to 25" x 11":
Visual Basic
c1r.Layout.PaperSize = PaperKind.Custom
c1r.Layout.CustomHeight = 25 * 1440 ' in twips
c1r.Layout.CustomWidth = 11 * 1440
C#
c1r.Layout.PaperSize = PaperKind.Custom;
c1r.Layout.CustomHeight = 25 * 1440; // in twips
c1r.Layout.CustomWidth = 11 * 1440;
Sample Report Available
For the complete report, see report "02: Custom Paper Size" in the CommonTasks.xml report definition file,
which is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Formatting Reports
The following topics show how to apply formatting to your report. By simply modifying properties in the
Properties window or adding a few lines of script to your VBScript expression, you can visually enhance your
report.
38
373
Adding Alternating Background Color
To create a report with alternating background color, use the OnPrint property of the Detail section to change the
BackColor property of the section. To do this, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select the report from the drop-down list above the Properties window.
5.
Locate the OnOpen property and enter cnt = 0. This initializes the cnt variable.
6.
Next, select Detail from the drop-down list above the Properties window.
7.
Locate the OnPrint property and click the empty field next to it, and then click the ellipsis button.
8.
The VBScrpit Editor appears. Enter the following VBScript expression in the code editor:
cnt = cnt + 1
if cnt mod 2 = 0 then
detail.backcolor = rgb(200,220,200)
else
detail.backcolor = rgb(255,255,255)
endif
9.
Click the Preview button to preview the report with alternating background.
This topic illustrates the following:
This report illustrates the alternating background color.
Whenever a Detail section is rendered, the counter is incremented and the BackColor property of the Detail
section is toggled.
Sample Report Available
For the complete report, see report "01: Alternating Background (Greenbar report)" in the CommonTasks.xml
report definition file, which is available for download from the CommonTasks sample on the ComponentOne
HelpCentral Sample page.
55
374
Adding Conditional Formatting
In some cases you may want to change a field's appearance depending on the data it represents. For example, you
may want to highlight items that are expensive, or low in stock. This can be done with script.
To do this, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select Detail from the drop-down list above the Properties window (since this section
contains the fields to add conditional formatting to).
5.
Locate the OnFormat property and click the empty field next to it, and then click the ellipsis button.
6.
The VBScript Editor appears. Enter the following VBScript expression in the code editor:
' VBScript: Detail.OnFormat
If UnitsInStock + UnitsOnOrder < ReorderLevel And _
Discontinued = False Then
Detail.BackColor = rgb(255,190,190)
Else
Detail.BackColor = vbWhite
Endif
The script changes the Detail section's BackColor property depending on the value of the fields
UnitsInStock, UnitsOnOrder, ReorderLevel, and Discontinued.
Sample Report Available
For the complete report, see report "16: Conditional Formatting" in the CommonTasks.xml report definition file,
which is available for download from the CommonTasks sample on the ComponentOne HelpCentral Sample page.
Editing the Field's Format Based on Value
You can change a report field's format based on its value by specifying an expression for the Detail section's
OnFormat property.
To specify an expression for the OnFormat property, complete the following steps:
1.
Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see
Accessing C1ReportDesigner from Visual Studio.
2.
Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you
can modify the report properties.
3.
Click the Close Print Preview button to begin editing the report.
4.
In Design mode, select Detail from the Property window's drop-down list to view the available properties
for the Detail section.
5.
Locate the OnFormat property and click the ellipsis button next to the property.
6.
The VBScript Editor appears where you can specify an expression.
The following expression changes the UnitsInStock field's ForeColor to red if the sum of the UnitsInStock
value and the UnitsOnOrder value is less than the ReorderLevel value. There are several ways to write this
expression.
Option 1:
Documents you may be interested
Documents you may be interested