Reports for WinForms | ComponentOne
In This Topic
    Drawing a Horizontal Line
    In This Topic

    This topic shows how to draw a horizontal line in the C1PrintDocument. Complete the following steps:

    1. Create a new Windows Forms application.
    2. Add a C1PrintPreviewControl control onto your form.
    3. Add a C1PrintDocument component onto your form, it will appear in the components' tray below the form. The preview will have the default name C1PrintPreview1, the document C1PrintDocument1.
    4. Set the value of the Document property of C1PrintPreview1 control to C1PrintDocument1, so that the preview will show the document when the application runs.
    5. Double click the form to create an event handler for the Form_Load event, this is where all code shown below will be written.
    6. A line can be drawn in C1PrintDocument using the RenderLine render object. Its two main properties are the two points the start and the end of the line. Because we will render the line into the block flow, and want it to be horizontal, we leave the Y coordinates of the two points as default zeroes. The start X coordinate is also left at zero. The end coordinate is set to the page width. This will result in a RenderLine object that renders a horizontal line across the whole page at the current Y coordinate of the block flow:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1PrintDocument1.StartDoc()    
      Dim rl As New C1.C1Preview.RenderLine(Me.C1PrintDocument1)   
      rl.X = Me.C1PrintDocument1.PageLayout.PageSettings.Width    
      Dim ld As New C1.C1Preview.LineDef("4mm", Color.SteelBlue)    
      Me.C1PrintDocument1.RenderBlockHorzLine(rl.X, ld)   
      Me.C1PrintDocument1.EndDoc()
      

      To write code in C#

      C#
      Copy Code
      this.c1PrintDocument1.StartDoc();    
      C1.C1Preview.RenderLine rl = new C1.C1Preview.RenderLine(this.c1PrintDocument1);   
      rl.X = this.c1PrintDocument1.PageLayout.PageSettings.Width;    
      C1.C1Preview.LineDef ld = new C1.C1Preview.LineDef("4mm", Color.SteelBlue);    
      this.c1PrintDocument1.RenderBlockHorzLine(rl.X, ld);    
      this.c1PrintDocument1.EndDoc();
      

    Run the program and observe the following:

    Your document will appear similar to the document below: