Reports for WinForms | ComponentOne
Getting Started with Reports for WinForms / Getting Started with Printing and Previewing / C1PrintDocument Quick Start / Step 3 of 4: Adding Code to the Project
In This Topic
    Step 3 of 4: Adding Code to the Project
    In This Topic

    Now that you've added the Reports for WinForms controls to the form and customized the form and controls, there's only one last step left before running the project. In this step you'll add code to the project to set the text that appears in the project.

    1. Double-click the form's title bar to switch to code view and create a handler for the Form_Load event.
    2. Add C1.Preview namespace and then the following code to the Form_Load event to add text to the preview document:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1PrintDocument1.Body.Children.Add(New C1.C1Preview.RenderText("Hello, World!"))
      

      To write code in C#

      C#
      Copy Code
      this.c1PrintDocument1.Body.Children.Add(new RenderText("Hello, World!"));
      
    3. Add the following code to the Form_Load event to generate the document:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1PrintDocument1.Generate()
      

      To write code in C#

      C#
      Copy Code
      this.c1PrintDocument1.Generate();
      

    You've added code to the project and completed step 3 of the printing and previewing quick start guide. In the last step you'll run the program.