Skip to main content Skip to footer

Managing Reports with Ease: Using ComponentOne Reports for WinForms

Applies To:

Studio Enterprise

Author:

Steve Basl

Published On:

5/7/2009

ComponentOne Reports for WinForms provides all the tools you need to meet your reporting, printing, previewing, and exporting needs. Moreover, it's extremely easy to use, requires little or no code, thus increasing productivity.

This article demonstrates these benefits and shows how to create a report, modify it, and export it to multiple formats. We'll start by creating a simple application and show how to load data in the report using an XML file. With the data loaded, we will next edit the data and save the changes to the report. Finally, we will save the report in multiple formats.

Step 1: Create a WinForms Application

ComponentOne Reports (C1Report) is a WinForms based control. We'll begin by creating a WinForms application in Microsoft Visual Studio.

Open Microsoft Visual Studio 2008, and select "File | New | Project" from the main menu. For this article, select Visual Basic as the language and select .NET Framework 2.0. Name the project "ReportDemo" in the Name field and click the OK button.

The project opens with your blank Windows Form. Next, we'll add the components to the form.

Step 2: Add Controls to the Form

In Visual Studio, go to your Toolbox and expand the ComponentOne Studio for WinForms tab. Locate the C1Report component and drag-and-drop it onto your form. The C1Report component is added to the component tray.

Return to the Toolbox, and drag-and-drop the C1PrintPreviewControl onto the form. With the C1PrintPreviewControl selected, go to the Properties window and set the Dock property to Fill.

Resize the Windows form to 700 (Width) by 500 (Height). Then, from the Properties window set its WindowState property to Maximized.

Step 1: Set the Viewer

Next, we'll set the viewer for C1Report. The C1Report control recognizes C1PrintPreviewControl and automatically adds it as the viewer for the report. Click the C1Report's smart tag to open the "C1Report Tasks" menu, and select C1PrintPreviewControl1 as the viewer for this document.

Step 2: Load the Report

Now we need to add the report to the application. To do this, click C1Report's smart tag to open the "C1Report Tasks" menu and click "Load Report". The "Select a report dialog" window appears. Click the ellipsis button adjacent to the File textbox to browse for your report file or database file. For this example, we will use the CalculatedChart.xml report, which you can download below.

[Download Calculated\_Chart\_Report.zip.](//cdn.mescius.io/assets/developer/blogs/legacy/c1/2009/5/Calculated_Chart_Report.zip)

Browse to the location you saved the CalculatedChart.xml, and click Open. Then select the Report drop-down arrow, select "New Report", and click the Load button. The file loads and displays information about the contents.

Click OK to close the window, and notice that your report is now displayed on the form in your application.

Print Preview Form

Now that we can view our report in the preview control, let's make some edits to the report before we export it.

Step 1: Open C1ReportDesigner

Select the C1Report component and click the smart tag to open the "C1Report Tasks" list. Select "Edit Report".

The ComponentOne ReportDesigner (C1ReportDesigner) opens. This is where you can make changes to your report and export and print your report with ease: no code required.

Step 2: Format the Text

Let's begin with some simple format edits to our report, making it more visually exciting. With the report open in C1ReportDesigner, we'll start by making some changes to the font. The current color is a light blue color; we'll go ahead and change it to red. To do this, complete the following steps:

  1. In the page layout, click and highlight the title "Chart With Calculated Data".
  2. Click the Properties tab in the left pane of the designer, and change the Text property to "Updated Chart With Calculated Data".
  3. Scroll to the top of the Properties window and change the ForeColor property to Red.
  4. Do the same to the ForeColor for "CategoryName", "ProductName", and "UnitPrice".

Step 2: Add an Image

You can also customize the report by adding images. To make room for the image above the title, select the title with your mouse pointer and drag it down the grid layout to somewhere around the 3-inches ruler position.

From the Ribbon's Design tab, locate the Add Unbound Picture button in the Fields group, and click it. Browse to a picture of your choice and click Open.

With your mouse pointer, click on the upper-left portion of your report and drag your mouse pointer to drop the image on the form.

Report Image

It's that easy to add an image, or any field, to your report.

Step 3: Preview the Report

The C1ReportDesigner also allows you to preview your report. Click the Preview button located in the Design tab of the Ribbon.

C1ReportDesigner gives you a preview of what your report will look like. You can quickly return to editing by selecting the Close Print Preview button.

Step 4: Save the Report

From the Application menu of the designer, select Save to save the report and use our newly updated report in our application.

Close the designer, and return to Visual Studio.

If the new report with the changes has not loaded in the preview control. Click C1Report's smart tag to open the "C1Report Tasks" menu, and select "Load Report". With the report already in the load field, click the Load button then click OK.

Press F5 to run the application. As you can see, we now have the entire report modified and we also added a picture to the report as well.

From the toolbar, click the Save button. This will allow us to effortlessly export this report to multiple formats.

Save as Type

For this sample we'll export the report to PDF format. Select "Adobe PDF" as the format, enter "ReportDemo" as the name, and click Save.

A PDF save window appears. Leave the default settings and click OK. By default the report will be saved in your Documents folder.

Below is the exported report in PDF format.

With little effort and zero coding, we were able to create a professional report, make a few modifications, and export it to a format of our choice. That's the power of Reports for WinForms.

Get started today. Download the trial version of ComponentOne Studio for WinForms or ComponentOne Studio Enterprise, both of which include the controls shown in this sample. You will also get dozens of reporting samples with full source code for quick learning.

[Download Studio for WinForms.](http://www.componentone.com/superproducts/studiowinforms/)

MESCIUS inc.

comments powered by Disqus