Reports for WinForms | ComponentOne
In This Topic
    Adding Columns to a Page
    In This Topic

    To add columns to a page, use the Add method.

    1. Navigate to the Toolbox, and 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.    
      this.c1PrintDocument1.Generate();
      

      To write code in C#

      C#
      Copy Code
      ' Make the document.    
      MakeDoc()
      
      ' Generate the document.    
      Me.C1PrintDocument1.Generate()
      
    4. Add the MakeDoc subroutine, which uses the Add method to add columns to all of the pages in the document:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub MakeDoc()
      
         ' Create page layout.    
         Dim pl As New C1.C1Preview.PageLayout
      
         ' Add columns.    
         pl.Columns.Add()    
         pl.Columns.Add()    
         pl.PageSettings = New C1.C1Preview.C1PageSettings()    
         Me.C1PrintDocument1.PageLayouts.Default = pl
      
         ' Create RenderText1.    
         Dim rt1 As New C1.C1Preview.RenderText    
         rt1.Text = "This is the house that Jack built. This is the carrot, that lay in the house that Jack built. This is the rat, that ate the carrot, that lay in the house that Jack built. This is the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built."
      
         ' Insert column break.    
         rt1.BreakAfter = C1.C1Preview.BreakEnum.Column
      
         ' Create RenderText2.    
         Dim rt2 As New C1.C1Preview.RenderText    
         rt2.Text = "This is the dog that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack  built. This is the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack  built."
      
         ' Insert column break.    
         rt2.BreakAfter = C1.C1Preview.BreakEnum.Column
      
         ' Create RenderText3.    
         Dim rt3 As New C1.C1Preview.RenderText    
         rt3.Text = "This is the priest all shaven and shorn, that married the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the cock that crowed in the morn, that waked the priest all shaven and shorn, that married the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the farmer sowing the corn, that kept the cock that crowed in the morn, that waked the priest all shaven and shorn, that married the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built."
      
         ' Add the RenderText to the document.    
         Me.C1PrintDocument1.Body.Children.Add(rt1)    
         Me.C1PrintDocument1.Body.Children.Add(rt2)    
         Me.C1PrintDocument1.Body.Children.Add(rt3)    
      End Sub
      

      To write code in C#

      C#
      Copy Code
      public void MakeDoc()    
      {
      
         // Create page layout.    
         C1.C1Preview.PageLayout pl = new C1.C1Preview.PageLayout();
      
         // Add columns.    
         pl.Columns.Add();    
         pl.Columns.Add();     
         pl.PageSettings = new C1.C1Preview.C1PageSettings();    
         this.c1PrintDocument1.PageLayouts.Default = pl;
      
         // Create RenderText1.    
         C1.C1Preview.RenderText rt1 = new C1.C1Preview.RenderText();    
         rt1.Text = "This is the house that Jack built. This is the carrot, that lay in the house that Jack built. This is the rat, that ate the carrot, that lay in the house that Jack built. This is the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built."; 
      
         // Insert column break.    
         rt1.BreakAfter = C1.C1Preview.BreakEnum.Column;
      
         // Create RenderText2.    
         C1.C1Preview.RenderText rt2 = new C1.C1Preview.RenderText();    
         rt2.Text = "This is the dog that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built.";
      
         // Insert column break.    
         rt2.BreakAfter = C1.C1Preview.BreakEnum.Column;
      
         // Create RenderText3.    
         C1.C1Preview.RenderText rt3 = new C1.C1Preview.RenderText();    
         rt3.Text = "This is the priest all shaven and shorn, that married the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the cock that crowed in the morn, that waked the priest all shaven and shorn, that married the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built. This is the farmer sowing the corn, that kept the cock that crowed in the morn, that waked the priest all shaven and shorn, that married the man all tattered and torn, that kissed the maiden all forlorn, that milked the cow with the crumbled horn, that tossed the dog, that worried the cat, that chased the rat, that ate the carrot, that lay in the house that Jack built.";
      
         // Add the RenderText to the document.    
         this.c1PrintDocument1.Body.Children.Add(rt1);    
         this.c1PrintDocument1.Body.Children.Add(rt2);    
         this.c1PrintDocument1.Body.Children.Add(rt3);    
      }
      

      What You've Accomplished

      The text appears in two columns on each page of the document: