Modifying the Font and Style of the Text
C1PrintDocument contains a RenderInLineText method that renders the specified string without starting a new paragraph into the block flow. The RenderInLineText method automatically wraps the text. This topic illustrates how to use the RenderInLineText method.
1. Create a new Windows Forms application. Add a C1PrintPreview control onto your form. 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. Set the value of the Document property of C1PrintPreview1 control to C1PrintDocument1, so that the preview will show the document when the application runs.
2. Double click the form to create a handler for the Form_Load event – this is where all code shown below will be written.
3. 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 ");
4. 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.");
5. 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);
6. End the document with the EndDoc method.
Me.C1PrintDocument1.EndDoc()
• C#
this.c1PrintDocument1.EndDoc();
Run the program and observe the following:
The text should appear similar to the text below:
|