Reports for WinForms | ComponentOne
In This Topic
    Inserting a Page Break
    In This Topic

    To insert a page break, use the BreakAfter property for the RenderObject.

    1. From the Toolbox, add the C1PrintPreviewControl and C1PrintDocument controls to your project.
    2. Click C1PrintPreviewControl1 to select it and in the Properties window set its Document property to C1PrintDocument1.
    3. Add the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' Make the document.    
      MakeDoc()
      
      ' Generate the document.    
      Me.C1PrintDocument1.Generate()
      

      To write code in C#

      C#
      Copy Code
      // Make the document.    
      MakeDoc();
      
      // Generate the document.    
      this.c1PrintDocument1.Generate();
      
    4. Add the MakeDoc subroutine, which uses the BreakAfter property to insert a page break after each RenderObject:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub MakeDoc()
      
          ' Create RenderText.    
          Dim rt1 As New C1.C1Preview.RenderText    
          rt1.Text = "This is RenderText. A RenderImage will be on page 2 and a RenderGraphic on page 3."
      
          ' Add a page break.    
          rt1.BreakAfter = C1.C1Preview.BreakEnum.Page
      
          ' Create RenderImage.    
          Dim ri1 As New C1.C1Preview.RenderImage    
          ri1.Image = System.Drawing.Image.FromFile("c:\c1logo.bmp")
      
          ' Add a page break.    
          ri1.BreakAfter = C1.C1Preview.BreakEnum.Page
      
          ' Create a RenderGraphic.    
          Dim rg1 As New C1.C1Preview.RenderGraphics()    
          rg1.Graphics.FillEllipse(Brushes.DarkBlue, 200, 200, 150, 150)    
          rg1.Graphics.FillPie(Brushes.DarkRed, 200, 200, 150, 150, -45, 75)
      
          ' Add the RenderObjects to the document.    
          Me.C1PrintDocument1.Body.Children.Add(rt1)    
          Me.C1PrintDocument1.Body.Children.Add(ri1)    
          Me.C1PrintDocument1.Body.Children.Add(rg1)    
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void MakeDoc()    
      {    
          // Create RenderText.    
          C1.C1Preview.RenderText rt1 = new C1.C1Preview.RenderText();    
          rt1.Text = "This is RenderText. A RenderImage will be on page 2 and a RenderGraphic on page 3.";
      
          // Add a page break.    
          rt1.BreakAfter = C1.C1Preview.BreakEnum.Page;
      
          // Create RenderImage.    
          C1.C1Preview.RenderImage ri1 = new C1.C1Preview.RenderImage();    
          ri1.Image = System.Drawing.Image.FromFile("c:\\c1logo.bmp");
      
          // Add a page break.    
          ri1.BreakAfter = C1.C1Preview.BreakEnum.Page;
      
          // Create a RenderGraphic.    
          C1.C1Preview.RenderGraphics rg1 = new C1.C1Preview.RenderGraphics();    
          rg1.Graphics.FillEllipse(Brushes.DarkBlue, 200, 200, 150, 150);    
          rg1.Graphics.FillPie(Brushes.DarkRed, 200, 200, 150, 150, -45, 75);
      
          // Add the RenderObjects to the document.    
          this.c1PrintDocument1.Body.Children.Add(rt1);    
          this.c1PrintDocument1.Body.Children.Add(ri1);    
          this.c1PrintDocument1.Body.Children.Add(rg1);    
      }
      

    What You've Accomplished

    A page break is inserted between the different RenderObjects: