StringFormat.SetMeasurableCharacterRanges メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StringFormat.SetMeasurableCharacterRanges メソッドの意味・解説 

StringFormat.SetMeasurableCharacterRanges メソッド

MeasureCharacterRanges メソッド呼び出したときに計測される文字範囲を表す CharacterRange 構造体配列指定します

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub SetMeasurableCharacterRanges ( _
    ranges As CharacterRange() _
)
Dim instance As StringFormat
Dim ranges As CharacterRange()

instance.SetMeasurableCharacterRanges(ranges)
public void SetMeasurableCharacterRanges (
    CharacterRange[] ranges
)
public:
void SetMeasurableCharacterRanges (
    array<CharacterRange>^ ranges
)
public void SetMeasurableCharacterRanges (
    CharacterRange[] ranges
)
public function SetMeasurableCharacterRanges
 (
    ranges : CharacterRange[]
)

パラメータ

ranges

MeasureCharacterRanges メソッド呼び出したときに計測される文字範囲を表す CharacterRange 構造体配列

戻り値
このメソッドは値を返しません。

例外例外
解説解説

32 文字超える範囲設定できないため、System.OverflowException発生します

使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

Public Sub SetMeasCharRangesExample(ByVal
 e As PaintEventArgs)
    Dim g As Graphics = e.Graphics
    Dim redBrush As New
 SolidBrush(Color.FromArgb(50, 255, 0, 0))

    ' Layout rectangles, font, and string format used for
    ' displaying string.
    Dim layoutRectA As New
 Rectangle(20, 20, 165, 80)
    Dim layoutRectB As New
 Rectangle(20, 110, 165, 80)
    Dim layoutRectC As New
 Rectangle(20, 200, 240, 80)
    Dim tnrFont As New Font("Times
 New Roman", 16)
    Dim strFormat As New
 StringFormat

    ' Ranges of character positions within a string.
    Dim charRanges As CharacterRange() = {New
 CharacterRange(3, 5), _
    New CharacterRange(15, 2), New CharacterRange(30,
 15)}

    ' Each region specifies the area occupied by the characters within
    ' a range of positions. The values are obtained by using a method
    ' that measures the character ranges.
    Dim charRegions(charRanges.Length) As [Region]

    ' String to be displayed.
    Dim str As String =
 _
    "The quick, brown fox easily jumps over the lazy dog."

    ' Set the char ranges for the string format.
    strFormat.SetMeasurableCharacterRanges(charRanges)

    ' Loop counter (unsigned 8-bit integer).
    Dim i As Byte


    ' Measure the char ranges for a given string and layout rectangle.
    ' Each area occupied by the characters in a range is stored as a
    ' region. then draw the string and layout rectangle and paint the
    ' regions.
    charRegions = g.MeasureCharacterRanges(str, tnrFont, _
    RectangleF.op_Implicit(layoutRectA), strFormat)
    g.DrawString(str, tnrFont, Brushes.Blue, _
    RectangleF.op_Implicit(layoutRectA), strFormat)
    g.DrawRectangle(Pens.Black, layoutRectA)

    ' Paint the regions.
    For i = 0 To charRegions.Length - 1
        g.FillRegion(redBrush, charRegions(i))
    Next i

    ' Repeat the above steps, but include trailing spaces in the char
    ' range measurement by setting the appropriate string format flag.
    strFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces
    charRegions = g.MeasureCharacterRanges(str, tnrFont, _
    RectangleF.op_Implicit(layoutRectB), strFormat)
    g.DrawString(str, tnrFont, Brushes.Blue, _
    RectangleF.op_Implicit(layoutRectB), strFormat)
    g.DrawRectangle(Pens.Black, layoutRectB)

    ' Paint the regions.
    For i = 0 To charRegions.Length - 1
        g.FillRegion(redBrush, charRegions(i))
    Next i

    ' Clear all the format flags.
    strFormat.FormatFlags = 0

    ' Repeat the steps, but use a different layout rectangle. The
    ' dimensions of the layout rectangle and the size of the font both
    ' affect the character range measurement.
    charRegions = g.MeasureCharacterRanges(str, tnrFont, _
    RectangleF.op_Implicit(layoutRectC), strFormat)
    g.DrawString(str, tnrFont, Brushes.Blue, _
    RectangleF.op_Implicit(layoutRectC), strFormat)
    g.DrawRectangle(Pens.Black, layoutRectC)

    ' Paint the regions.
    For i = 0 To charRegions.Length - 1
        g.FillRegion(redBrush, charRegions(i))
    Next i
End Sub
public void SetMeasCharRangesExample(PaintEventArgs
 e)
{
    Graphics     g = e.Graphics;
    SolidBrush   redBrush = new SolidBrush(Color.FromArgb(50,
 255, 0, 0));
             
    // Layout rectangles, font, and string format used for displaying
 string.
    Rectangle    layoutRectA = new Rectangle(20, 20, 165, 80);
    Rectangle    layoutRectB = new Rectangle(20, 110, 165, 80);
    Rectangle    layoutRectC = new Rectangle(20, 200, 240, 80);
    Font         tnrFont = new Font("Times New Roman",
 16);
    StringFormat strFormat = new StringFormat();
             
    // Ranges of character positions within a string.
    CharacterRange[] charRanges = { new CharacterRange(3, 5),
        new CharacterRange(15, 2), new CharacterRange(30,
 15)};
             
    // Each region specifies the area occupied by the characters within
 a
    // range of positions. the values are obtained by using a method
 that
    // measures the character ranges.
    Region[]     charRegions = new Region[charRanges.Length];
             
    // String to be displayed.
    string  str =
        "The quick, brown fox easily jumps over the lazy dog.";
             
    // Set the char ranges for the string format.
    strFormat.SetMeasurableCharacterRanges(charRanges);
   
    // loop counter (unsigned 8-bit integer)
    byte  i;    
   
    // Measure the char ranges for a given string and layout rectangle.
 Each
    // area occupied by the characters in a range is stored as a region.
 Then
    // draw the string and layout rectangle, and paint the regions.
    charRegions = g.MeasureCharacterRanges(str, tnrFont,
        layoutRectA, strFormat);
   g.DrawString(str, tnrFont, Brushes.Blue, layoutRectA, strFormat);
    g.DrawRectangle(Pens.Black, layoutRectA);
     
    // Paint the regions.
    for (i = 0; i < charRegions.Length; i++)
        g.FillRegion(redBrush, charRegions[i]);   
   
             
    // Repeat the above steps, but include trailing spaces in the char
    // range measurement by setting the appropriate string format flag.
    strFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
    charRegions = g.MeasureCharacterRanges(str, tnrFont,
        layoutRectB, strFormat);
    g.DrawString(str, tnrFont, Brushes.Blue, layoutRectB, strFormat);
    g.DrawRectangle(Pens.Black, layoutRectB);
     
    
    for (i = 0; i < charRegions.Length; i++)
        g.FillRegion(redBrush, charRegions[i]);   
   
    // Clear all the format flags.
    strFormat.FormatFlags = 0;                   
 
    // Repeat the steps, but use a different layout rectangle. the dimensions
    // of the layout rectangle and the size of the font both affect
 the
    // character range measurement.
    charRegions = g.MeasureCharacterRanges(str, tnrFont,
        layoutRectC, strFormat);
    g.DrawString(str, tnrFont, Brushes.Blue, layoutRectC, strFormat);
    g.DrawRectangle(Pens.Black, layoutRectC);
    
    // Paint the regions.
    for (i = 0; i < charRegions.Length; i++)
        g.FillRegion(redBrush, charRegions[i]);   
    
}
void SetMeasCharRangesExample( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;
   SolidBrush^ redBrush = gcnew SolidBrush( Color::FromArgb( 50, 255, 0, 0 ) );

   // Layout rectangles, font, and string format used for displaying
 string.
   Rectangle layoutRectA = Rectangle(20,20,165,80);
   Rectangle layoutRectB = Rectangle(20,110,165,80);
   Rectangle layoutRectC = Rectangle(20,200,240,80);
   System::Drawing::Font^ tnrFont = gcnew System::Drawing::Font( "Times New
 Roman",16 );
   StringFormat^ strFormat = gcnew StringFormat;

   // Ranges of character positions within a string.
   array<CharacterRange>^ charRanges = {CharacterRange(3,5),CharacterRange(15
,2),CharacterRange(30,15)};

   // Each region specifies the area occupied by the characters within
 a
   // range of positions. the values are obtained by using a method
 that
   // measures the character ranges.
   array<System::Drawing::Region^>^charRegions = gcnew array<System::Drawing::Region^>(charRanges->Length);

   // String to be displayed.
   String^ str = "The quick, brown fox easily jumps over the lazy dog.";

   // Set the char ranges for the string format.
   strFormat->SetMeasurableCharacterRanges( charRanges );

   // loop counter (unsigned 8-bit integer)
   Byte i;

   // Measure the char ranges for a given string and layout rectangle.
 Each
   // area occupied by the characters in a range is stored as a region.
 Then
   // draw the string and layout rectangle, and paint the regions.
   charRegions = g->MeasureCharacterRanges( str, tnrFont, layoutRectA, strFormat
 );
   g->DrawString( str, tnrFont, Brushes::Blue, layoutRectA, strFormat );
   g->DrawRectangle( Pens::Black, layoutRectA );

   // Paint the regions.
   for ( i = 0; i < charRegions->Length; i++ )
      g->FillRegion( redBrush, charRegions[ i ] );

   // Repeat the above steps, but include trailing spaces in the char
   // range measurement by setting the appropriate string format flag.
   strFormat->FormatFlags = StringFormatFlags::MeasureTrailingSpaces;
   charRegions = g->MeasureCharacterRanges( str, tnrFont, layoutRectB, strFormat
 );
   g->DrawString( str, tnrFont, Brushes::Blue, layoutRectB, strFormat );
   g->DrawRectangle( Pens::Black, layoutRectB );
   for ( i = 0; i < charRegions->Length; i++ )
      g->FillRegion( redBrush, charRegions[ i ] );

   // Clear all the format flags.
   strFormat->FormatFlags = StringFormatFlags(0);

   // Repeat the steps, but use a different layout rectangle. the dimensions
   // of the layout rectangle and the size of the font both affect the
   // character range measurement.
   charRegions = g->MeasureCharacterRanges( str, tnrFont, layoutRectC, strFormat
 );
   g->DrawString( str, tnrFont, Brushes::Blue, layoutRectC, strFormat );
   g->DrawRectangle( Pens::Black, layoutRectC );

   // Paint the regions.
   for ( i = 0; i < charRegions->Length; i++ )
      g->FillRegion( redBrush, charRegions[ i ] );
}
public void SetMeasCharRangesExample(PaintEventArgs
 e)
{
    Graphics g = e.get_Graphics();
    SolidBrush redBrush = new SolidBrush(Color.FromArgb(50, 255,
 0, 0));

    // Layout rectangles, font, and string format 
    // used for displaying string.
    Rectangle layoutRectA = new Rectangle(20, 20, 165, 80);
    Rectangle layoutRectB = new Rectangle(20, 110, 165, 80);
    Rectangle layoutRectC = new Rectangle(20, 200, 240, 80);
    Font tnrFont = new Font("Times New Roman", 16);
    StringFormat strFormat = new StringFormat();

    // Ranges of character positions within a string.
    CharacterRange charRanges[] =  { new CharacterRange(3, 5),
 
                                new CharacterRange(15, 2),
                                new CharacterRange(30, 15) };

    // Each region specifies the area occupied by the characters within
 a
    // range of positions. the values are obtained by using a method
 that
    // measures the character ranges.
    Region charRegions[] = new Region[charRanges.length];

    // String to be displayed.
    String str = "The quick, brown fox easily jumps over the lazy dog.";

    // Set the char ranges for the string format.
    strFormat.SetMeasurableCharacterRanges(charRanges);

    // loop counter (unsigned 8-bit integer)
    ubyte i;

    // Measure the char ranges for a given string and layout rectangle.Each
    // area occupied by the characters in a range is stored as a region.
 
    // Then draw the string and layout rectangle, and paint the regions.
    charRegions = g.MeasureCharacterRanges(str, tnrFont, 
                RectangleF.op_Implicit(layoutRectA), strFormat);
    g.DrawString(str, tnrFont, Brushes.get_Blue(), 
        RectangleF.op_Implicit(layoutRectA), strFormat);
    g.DrawRectangle(Pens.get_Black(), layoutRectA);

    // Paint the regions.
    for (i = 0; i < charRegions.length; i++) {
        g.FillRegion(redBrush, charRegions[i]);
    }

    // Repeat the above steps, but include trailing spaces in the char
    // range measurement by setting the appropriate string format flag.
    strFormat.set_FormatFlags(StringFormatFlags.MeasureTrailingSpaces);
    charRegions = g.MeasureCharacterRanges(str, tnrFont, 
                RectangleF.op_Implicit(layoutRectB), strFormat);
    g.DrawString(str, tnrFont, Brushes.get_Blue(), 
        RectangleF.op_Implicit(layoutRectB), strFormat);
    g.DrawRectangle(Pens.get_Black(), layoutRectB);
    for (i = 0; i < charRegions.length; i++) {
        g.FillRegion(redBrush, charRegions[i]);
    }

    // Clear all the format flags.
    strFormat.set_FormatFlags((StringFormatFlags)0);

    // Repeat the steps, but use a different layout rectangle.
    //  the dimensions of the layout rectangle and the size of the font
    //  both affect the character range measurement.
    charRegions = g.MeasureCharacterRanges(str, tnrFont, 
                RectangleF.op_Implicit(layoutRectC), strFormat);
    g.DrawString(str, tnrFont, Brushes.get_Blue(), 
        RectangleF.op_Implicit(layoutRectC), strFormat);
    g.DrawRectangle(Pens.get_Black(), layoutRectC);

    // Paint the regions.
    for (i = 0; i < charRegions.length; i++) {
        g.FillRegion(redBrush, charRegions[i]);
    }
} //SetMeasCharRangesExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からStringFormat.SetMeasurableCharacterRanges メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からStringFormat.SetMeasurableCharacterRanges メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からStringFormat.SetMeasurableCharacterRanges メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「StringFormat.SetMeasurableCharacterRanges メソッド」の関連用語

StringFormat.SetMeasurableCharacterRanges メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StringFormat.SetMeasurableCharacterRanges メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS