Reports for WinForms
C1PrintDocument 内のテキストのフォントとスタイルを変更する
クイックスタート > 印刷プレビューを開始する > 文字列を追加する > C1PrintDocument 内のテキストのフォントとスタイルを変更する

C1PrintDocument には、指定された文字列を新しい段落を開始せずにブロックフローにレンダリングする RenderInLineText メソッドがあります。RenderInLineText メソッドはテキストを自動的にラップします。このトピックでは、RenderInLineText メソッドの使用方法を示します。

  1. 新しい Windows フォームアプリケーションを作成します。C1PrintPreview コントロールをフォームに追加します。C1PrintDocument コンポーネントをフォームに追加します。これは、フォームの下のコンポーネントのトレイに表示されます。プレビューには c1PrintPreview1、ドキュメントには c1PrintDocument1 のデフォルト名が与えられます。c1PrintPreview1 コントロールの Document プロパティの値を c1PrintDocument1 に設定します。これにより、アプリケーションの実行時にプレビューにドキュメントが表示されます。
  2. フォームをダブルクリックして、フォームロードイベントのハンドラを作成します。ここに、以下のすべてのコードを記述します。
  3. StartDoc メソッドでドキュメントを開始し、デフォルトのフォントを使ってテキスト行を作成します。次に例を示します。

    Visual Basic コードの書き方

    Visual Basic
    コードのコピー
    Me.C1PrintDocument1.StartDoc()    
    Me.C1PrintDocument1.RenderInlineText("With C1PrintDocument you can print ")
    

    C# コードの書き方

    C#
    コードのコピー
    this.c1PrintDocument1.StartDoc();    
    this.c1PrintDocument1.RenderInlineText("With C1PrintDocument you can print ");
    
  4. 別のフォントと色で続行し、デフォルトのフォントと色に戻ります。

    Visual Basic コードの書き方

    Visual Basic
    コードのコピー
    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# コードの書き方

    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. 行内の最後の数ワードを緑色にします。

    Visual Basic コードの書き方

    Visual Basic
    コードのコピー
    Me.C1PrintDocument1.RenderInlineText(" The text wraps automatically, so your life becomes easier.", Color.Green)
    

    C# コードの書き方

    C#
    コードのコピー
    this.c1PrintDocument1.RenderInlineText(" The text wraps automatically, so your life becomes easier.", Color.Green);
    
  6.  EndDoc メソッドでドキュメントを終了します。

    Visual Basic コードの書き方

    Visual Basic
    コードのコピー
    Me.C1PrintDocument1.EndDoc()
    

    C# コードの書き方

    C#
    コードのコピー
    this.c1PrintDocument1.EndDoc();
    

プログラムを実行し、次の点を確認します。

テーブルは次のように表示されます。