バージョン

フォント

テキストがなければレポートを書くことができません。したがってフォントはレポートを記述する上で不可欠な要素です。もちろん、テキストにすべてのデフォルト設定を使用することは可能ですが、これらのデフォルトもフォントを使用します(デフォルトのフォントは Arial、12 pt です)。フォントを定義するために必要なのは、名前とサイズだけです。FontStyle やフォントの位置など、 (システムの Fonts フォルダーにない場合に) フォントを定義する時にその他のオプションも提供する Font コンストラクターには複数のオーバーロードがあります。プロパティによってフォントに追加できるスタイルは多数あり、以下に例を示します。

これらの各スタイルは、FontStyle 列挙体でも使用可能で、Style プロパティを設定する時に使用されます。Fonts クラスを使用して、事前に定義されたフォントとスタイルのコレクションにアクセスすることも可能です。Fonts クラスの各フォントはシールされており、スタイルを修正できないことに留意してください(たとえば、Bold や Underline を追加)。


以下のコード例では、2 つのフォントを定義して Text 要素でこれらのフォントを使用する Font オブジェクトの一般的な使用例を示しています。

  1. Font オブジェクトを定義します。

    Visual Basic の場合:

    Imports Infragistics.Documents.Reports.Report
    Imports Infragistics.Documents.Reports.Graphics
    .
    .
    .
    ' Define two font objects.
    Dim verdanaBigItalic As New Font("Verdana", 18, FontStyle.Italic)
    Dim verdanaSmallBold As New Font("Verdana", 10, FontStyle.Bold)
    

    C# の場合:

    using Infragistics.Documents.Reports.Report;
    using Infragistics.Documents.Reports.Graphics;
    .
    .
    .
    // Define two font objects.
    Font verdanaBigItalic = new Font("Verdana", 18, FontStyle.Italic);
    Font verdanaSmallBold = new Font("Verdana", 10, FontStyle.Bold);
    
  2. 3 つの Text 要素をメインのセクション(section1)に追加して、スタイルを設定します。

    Visual Basic の場合:

    ' Add a new Text element to the section and store the 
    ' reference fontText. Then set the style using the font
    ' created earlier and use a black brush.
    Dim fontText As Infragistics.Documents.Reports.Report.Text.IText = section1.AddText()
    fontText.Margins = New Margins(0, 3)
    fontText.Style = _
      New Infragistics.Documents.Reports.Report.Text.Style(verdanaBigItalic, Brushes.Black)
    fontText.AddContent("This font is Verdana, 18 pt., and Italic")
    
    ' Add another text element.
    fontText = section1.AddText()
    fontText.Margins = New Margins(0, 3)
    fontText.Style = _
      New Infragistics.Documents.Reports.Report.Text.Style(verdanaSmallBold, Brushes.Black)
    fontText.AddContent("This font is Verdana, 10 pt., and Bold")
    
    ' Add another text element; this time using a predefined font
    ' and changing the color to red.
    fontText = section1.AddText()
    fontText.Margins = New Margins(0, 3)
    fontText.Style = _
      New Infragistics.Documents.Reports.Report.Text.Style( _
      Fonts.TimesNewRomanBold, Brushes.Red)
    fontText.AddContent("This font is a predefined font: Fonts.TimesNewRomanBold")
    

    C# の場合:

    // Add a new Text element to the section and store the 
    // reference fontText. Then set the style using the font
    // created earlier and use a black brush.
    Infragistics.Documents.Reports.Report.Text.IText fontText = section1.AddText();
    fontText.Margins = new Margins(0, 3);
    fontText.Style = 
      new Infragistics.Documents.Reports.Report.Text.Style(verdanaBigItalic, Brushes.Black);
    fontText.AddContent("This font is Verdana, 18 pt., and Italic");
    
    // Add another text element.
    fontText = section1.AddText();
    fontText.Margins = new Margins(0, 3);
    fontText.Style = 
      new Infragistics.Documents.Reports.Report.Text.Style(verdanaSmallBold, Brushes.Black);
    fontText.AddContent("This font is Verdana, 10 pt., and Bold");
    
    // Add another text element; this time using a predefined font
    // and changing the color to red.
    fontText = section1.AddText();
    fontText.Margins = new Margins(0, 3);
    fontText.Style = 
      new Infragistics.Documents.Reports.Report.Text.Style( 
      Fonts.TimesNewRomanBold, Brushes.Red);
    fontText.AddContent("This font is a predefined font: Fonts.TimesNewRomanBold");
    

オンラインで表示: GitHub