ComponentOne Preview Classic for WinForms: Preview Classic for WinForms Task-Based Help > Reading a Text File in a C1PrintPreview Control

Reading a Text File in a C1PrintPreview Control

To read a text file in a C1PrintPreview control, read the file into a stream and render the text using the RenderBlockText method. Add the following code to the Form_Load event:

      Visual Basic

Dim s As String

 

' Read the file into a stream.

Dim sr As New IO.StreamReader("c:\textfile.txt")

 

' Pass the stream to string.

s = sr.ReadToEnd

 

Me.C1PrintDocument1.StartDoc()

 

' Render the text using the RenderBlockText method.

Me.C1PrintDocument1.RenderBlockText(s, New Font("Courier New", 10))

 

Me.C1PrintDocument1.EndDoc()

      C#

string s;

 

// Read the file into a stream.

IO.StreamReader sr = new IO.StreamReader(@"c:\textfile.txt");

 

// Pass the stream to a string.

s = sr.ReadToEnd;

 

this.c1PrintDocument1.StartDoc();

 

// Render the text using the RenderBlockText method.

this.c1PrintDocument1.RenderBlockText(s, new Font("Courier New", 10));

 

this.c1PrintDocument1.EndDoc();


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.