Modifying the Font and Style of the Text in the C1PrintDocument
Modifying the font and style of the text in C1PrintDocument illustrates how to use the RenderInLineText method. The RenderInLineText method renders a specified string without starting a new paragraph into the block flow, and automatically wraps the text.
1. Create a new Windows Forms application. Drag and drop a C1PrintPreview control onto your form. Drag and drop 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. Set the value of the Document property of c1PrintPreview1 control to c1PrintDocument1, so that the preview will show the document when the application runs. Double click on the form to create a handler for the Form_Load event – this is where all code shown below will be written.
2. Begin the document with the StartDoc method and create a line of text using the default font. For example:
Me.C1PrintDocument1.StartDoc()
Me.C1PrintDocument1.RenderInlineText("With C1PrintDocument you can print ")
• C#
this.c1PrintDocument1.StartDoc();
this.c1PrintDocument1.RenderInlineText("With C1PrintDocument you can print ");
3. Continue with a different font and color and then go back to the default font and color:
Me.C1PrintDocument1.RenderInlineText("Line by Line", New Font("Times New Roman", 30, FontStyle.Bold), Color.FromArgb(0, 0, 125))
Me.C1PrintDocument1.RenderInlineText(" and modify text attributes as you go.")
• C#
this.c1PrintDocument1.RenderInlineText("Line by Line", new Font("Times New Roman", 30, FontStyle.Bold), Color.FromArgb(0, 0, 125));
this.c1PrintDocument1.RenderInlineText(" and modify text attributes as you go.");
4. 'Make the last few words of the line a green color.
Me.C1PrintDocument1.RenderInlineText(" The text wraps automatically, so your life becomes easier.", Color.Green)
• C#
this.c1PrintDocument1.RenderInlineText(" The text wraps automatically, so your life becomes easier.", Color.Green);
5. End the document with the EndDoc method.
Me.C1PrintDocument1.EndDoc()
• C#
this.c1PrintDocument1.EndDoc();
Run the program and observe the following:
The text should look like this:
|