CharacterRangeとは? わかりやすく解説

CharacterRange コンストラクタ

CharacterRange 構造新しインスタンス初期化して文字列内における文字位置範囲指定します

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

public CharacterRange (
    int First,
    int Length
)
public:
CharacterRange (
    int First, 
    int Length
)
public CharacterRange (
    int First, 
    int Length
)
public function CharacterRange (
    First : int, 
    Length : int
)

パラメータ

First

範囲内最初文字位置。たとえば、First を 0 に設定すると、この範囲開始位置は文字列の位置 0 になります

Length

範囲内位置の数。

使用例使用例

CharacterRange作成し、これを利用して文字列一部強調表示する方法次のコード例示します。この例は、Windows フォームでの使用意図してデザインされています。コードフォーム貼り付けフォームPaint イベント処理するときに PaintEventArgs の e渡して HighlightACharacterRange メソッド呼び出します。

Private Sub HighlightACharacterRange(ByVal
 e As PaintEventArgs)

    ' Declare the string to draw.
    Dim message As String
 = _
        "This is the string to highlight a word in."

    ' Declare the word to highlight.
    Dim searchWord As String
 = "string"

    ' Create a CharacterRange array with the searchWord 
    ' location and length.
    Dim ranges() As CharacterRange = _
        New CharacterRange() _
            {New CharacterRange(message.IndexOf(searchWord), _
            searchWord.Length)}

    ' Construct a StringFormat object.
    Dim stringFormat1 As New
 StringFormat

    ' Set the ranges on the StringFormat object.
    stringFormat1.SetMeasurableCharacterRanges(ranges)

    ' Declare the font to write the message in.
    Dim largeFont As Font = New
 Font(FontFamily.GenericSansSerif, _
        16.0F, GraphicsUnit.Pixel)

    ' Construct a new Rectangle.
    Dim displayRectangle As New
 Rectangle(20, 20, 200, 100)

    ' Convert the Rectangle to a RectangleF.
    Dim displayRectangleF As RectangleF = _
        RectangleF.op_Implicit(displayRectangle)

    ' Get the Region to highlight by calling the 
    ' MeasureCharacterRanges method.
    Dim charRegion() As Region = _
        e.Graphics.MeasureCharacterRanges(message, _
        largeFont, displayRectangleF, stringFormat1)

    ' Draw the message string on the form.
    e.Graphics.DrawString(message, largeFont, Brushes.Blue, _
        displayRectangleF)

    ' Fill in the region using a semi-transparent color.
    e.Graphics.FillRegion(New SolidBrush(Color.FromArgb(50, _
        Color.Fuchsia)), charRegion(0))

End Sub
private void HighlightACharacterRange(PaintEventArgs
 e)
{

    // Declare the string to draw.
    string message = "This is the string
 to highlight a word in.";

    // Declare the word to highlight.
    string searchWord = "string";

    // Create a CharacterRange array with the searchWord 
    // location and length.
    CharacterRange[] ranges = 
        new CharacterRange[]{new CharacterRange
        (message.IndexOf(searchWord), searchWord.Length)};

    // Construct a StringFormat object.
    StringFormat stringFormat1 = new StringFormat();

    // Set the ranges on the StringFormat object.
    stringFormat1.SetMeasurableCharacterRanges(ranges);

    // Declare the font to write the message in.
    Font largeFont = new Font(FontFamily.GenericSansSerif, 16.0F
,
        GraphicsUnit.Pixel);

    // Construct a new Rectangle.
    Rectangle displayRectangle = new Rectangle(20, 20, 200, 100);

    // Convert the Rectangle to a RectangleF.
    RectangleF displayRectangleF = (RectangleF)displayRectangle;

    // Get the Region to highlight by calling the 
    // MeasureCharacterRanges method.
    Region[] charRegion = e.Graphics.MeasureCharacterRanges(message, 
        largeFont, displayRectangleF, stringFormat1);

    // Draw the message string on the form.
    e.Graphics.DrawString(message, largeFont, Brushes.Blue, 
        displayRectangleF);

    // Fill in the region using a semi-transparent color.
    e.Graphics.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Fuchsia)),
 
        charRegion[0]);

    largeFont.Dispose();

}
void HighlightACharacterRange( PaintEventArgs^ e )
{
   // Declare the string to draw.
   String^ message = "This is the string to highlight a word
 in.";

   // Declare the word to highlight.
   String^ searchWord = "string";

   // Create a CharacterRange array with the searchWord 
   // location and length.
   array<CharacterRange>^ temp = {CharacterRange( message->IndexOf( searchWord
 ), searchWord->Length )};
   array<CharacterRange>^ranges = temp;

   // Construct a StringFormat object.
   StringFormat^ stringFormat1 = gcnew StringFormat;

   // Set the ranges on the StringFormat object.
   stringFormat1->SetMeasurableCharacterRanges( ranges );

   // Declare the font to write the message in.
   System::Drawing::Font^ largeFont = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,16.0F,GraphicsUnit::Pixel
 );

   // Construct a new Rectangle.
   Rectangle displayRectangle = Rectangle(20,20,200,100);

   // Convert the Rectangle to a RectangleF.
   RectangleF displayRectangleF = displayRectangle;

   // Get the Region to highlight by calling the 
   // MeasureCharacterRanges method.
   array<System::Drawing::Region^>^charRegion = e->Graphics->MeasureCharacterRanges(
 message, largeFont, displayRectangleF, stringFormat1 );

   // Draw the message string on the form.
   e->Graphics->DrawString( message, largeFont, Brushes::Blue, displayRectangleF
 );

   // Fill in the region using a semi-transparent color.
   e->Graphics->FillRegion( gcnew SolidBrush( Color::FromArgb( 50, Color::Fuchsia
 ) ), charRegion[ 0 ] );
   delete largeFont;
}
private void HighlightACharacterRange(PaintEventArgs
 e)
{
    // Declare the string to draw.
    String message = "This is the string to highlight a word
 in.";
    // Declare the word to highlight.
    String searchWord = "string";
    // Create a CharacterRange array with the searchWord 
    // location and length.
    CharacterRange ranges[] = new CharacterRange[] 
        { new CharacterRange(message.IndexOf(searchWord), 
        searchWord.get_Length()) };
    // Construct a StringFormat object.
    StringFormat stringFormat1 = new StringFormat();
    // Set the ranges on the StringFormat object.
    stringFormat1.SetMeasurableCharacterRanges(ranges);
    // Declare the font to write the message in.
    Font largeFont = new Font(FontFamily.get_GenericSansSerif(),
 
        16, GraphicsUnit.Pixel);
    // Construct a new Rectangle.
    Rectangle displayRectangle = new Rectangle(20, 20, 200, 100);
    // Convert the Rectangle to a RectangleF.
    RectangleF displayRectangleF = RectangleF.op_Implicit(displayRectangle);
    // Get the Region to highlight by calling the 
    // MeasureCharacterRanges method.
    Region charRegion[] = e.get_Graphics().MeasureCharacterRanges(message, 
        largeFont, displayRectangleF, stringFormat1);
    // Draw the message string on the form.
    e.get_Graphics().DrawString(message, largeFont, Brushes.get_Blue(),
        displayRectangleF);
    // Fill in the region using a semi-transparent color.
    e.get_Graphics().FillRegion(new SolidBrush(Color.FromArgb(50,
 
        Color.get_Fuchsia())), charRegion[0]);
    largeFont.Dispose();
} //HighlightACharacterRange
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

CharacterRange プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ First CharacterRange の、最初文字文字列位置取得または設定します
パブリック プロパティ Length CharacterRange 内の位置の数を取得または設定します
参照参照

関連項目

CharacterRange 構造体
System.Drawing 名前空間

CharacterRange メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CharacterRange 構造体
System.Drawing 名前空間

CharacterRange メンバ

文字列内における文字位置範囲指定します

CharacterRange データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド CharacterRange CharacterRange 構造新しインスタンス初期化して文字列内における文字位置範囲指定します
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ First CharacterRange の、最初文字文字列位置取得または設定します
パブリック プロパティ Length CharacterRange 内の位置の数を取得または設定します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CharacterRange 構造体
System.Drawing 名前空間

CharacterRange 構造体

文字列内における文字位置範囲指定します

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

Dim instance As CharacterRange
public struct CharacterRange
public value class CharacterRange
public final class CharacterRange extends ValueType
JScript では、構造体使用できますが、新規に宣言することはできません。
使用例使用例

CharacterRange作成し、これを利用して文字列一部強調表示する方法次のコード例示します。この例は、Windows フォームでの使用意図してデザインされています。コードフォーム貼り付けフォームPaint イベント処理するときに PaintEventArgs の e渡して HighlightACharacterRange メソッド呼び出します。

Private Sub HighlightACharacterRange(ByVal
 e As PaintEventArgs)

    ' Declare the string to draw.
    Dim message As String
 = _
        "This is the string to highlight a word in."

    ' Declare the word to highlight.
    Dim searchWord As String
 = "string"

    ' Create a CharacterRange array with the searchWord 
    ' location and length.
    Dim ranges() As CharacterRange = _
        New CharacterRange() _
            {New CharacterRange(message.IndexOf(searchWord), _
            searchWord.Length)}

    ' Construct a StringFormat object.
    Dim stringFormat1 As New
 StringFormat

    ' Set the ranges on the StringFormat object.
    stringFormat1.SetMeasurableCharacterRanges(ranges)

    ' Declare the font to write the message in.
    Dim largeFont As Font = New
 Font(FontFamily.GenericSansSerif, _
        16.0F, GraphicsUnit.Pixel)

    ' Construct a new Rectangle.
    Dim displayRectangle As New
 Rectangle(20, 20, 200, 100)

    ' Convert the Rectangle to a RectangleF.
    Dim displayRectangleF As RectangleF = _
        RectangleF.op_Implicit(displayRectangle)

    ' Get the Region to highlight by calling the 
    ' MeasureCharacterRanges method.
    Dim charRegion() As Region = _
        e.Graphics.MeasureCharacterRanges(message, _
        largeFont, displayRectangleF, stringFormat1)

    ' Draw the message string on the form.
    e.Graphics.DrawString(message, largeFont, Brushes.Blue, _
        displayRectangleF)

    ' Fill in the region using a semi-transparent color.
    e.Graphics.FillRegion(New SolidBrush(Color.FromArgb(50, _
        Color.Fuchsia)), charRegion(0))

End Sub
private void HighlightACharacterRange(PaintEventArgs
 e)
{

    // Declare the string to draw.
    string message = "This is the string
 to highlight a word in.";

    // Declare the word to highlight.
    string searchWord = "string";

    // Create a CharacterRange array with the searchWord 
    // location and length.
    CharacterRange[] ranges = 
        new CharacterRange[]{new CharacterRange
        (message.IndexOf(searchWord), searchWord.Length)};

    // Construct a StringFormat object.
    StringFormat stringFormat1 = new StringFormat();

    // Set the ranges on the StringFormat object.
    stringFormat1.SetMeasurableCharacterRanges(ranges);

    // Declare the font to write the message in.
    Font largeFont = new Font(FontFamily.GenericSansSerif, 16.0F
,
        GraphicsUnit.Pixel);

    // Construct a new Rectangle.
    Rectangle displayRectangle = new Rectangle(20, 20, 200, 100);

    // Convert the Rectangle to a RectangleF.
    RectangleF displayRectangleF = (RectangleF)displayRectangle;

    // Get the Region to highlight by calling the 
    // MeasureCharacterRanges method.
    Region[] charRegion = e.Graphics.MeasureCharacterRanges(message, 
        largeFont, displayRectangleF, stringFormat1);

    // Draw the message string on the form.
    e.Graphics.DrawString(message, largeFont, Brushes.Blue, 
        displayRectangleF);

    // Fill in the region using a semi-transparent color.
    e.Graphics.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Fuchsia)),
 
        charRegion[0]);

    largeFont.Dispose();

}
void HighlightACharacterRange( PaintEventArgs^ e )
{
   // Declare the string to draw.
   String^ message = "This is the string to highlight a word
 in.";

   // Declare the word to highlight.
   String^ searchWord = "string";

   // Create a CharacterRange array with the searchWord 
   // location and length.
   array<CharacterRange>^ temp = {CharacterRange( message->IndexOf( searchWord
 ), searchWord->Length )};
   array<CharacterRange>^ranges = temp;

   // Construct a StringFormat object.
   StringFormat^ stringFormat1 = gcnew StringFormat;

   // Set the ranges on the StringFormat object.
   stringFormat1->SetMeasurableCharacterRanges( ranges );

   // Declare the font to write the message in.
   System::Drawing::Font^ largeFont = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,16.0F,GraphicsUnit::Pixel
 );

   // Construct a new Rectangle.
   Rectangle displayRectangle = Rectangle(20,20,200,100);

   // Convert the Rectangle to a RectangleF.
   RectangleF displayRectangleF = displayRectangle;

   // Get the Region to highlight by calling the 
   // MeasureCharacterRanges method.
   array<System::Drawing::Region^>^charRegion = e->Graphics->MeasureCharacterRanges(
 message, largeFont, displayRectangleF, stringFormat1 );

   // Draw the message string on the form.
   e->Graphics->DrawString( message, largeFont, Brushes::Blue, displayRectangleF
 );

   // Fill in the region using a semi-transparent color.
   e->Graphics->FillRegion( gcnew SolidBrush( Color::FromArgb( 50, Color::Fuchsia
 ) ), charRegion[ 0 ] );
   delete largeFont;
}
private void HighlightACharacterRange(PaintEventArgs
 e)
{
    // Declare the string to draw.
    String message = "This is the string to highlight a word
 in.";
    // Declare the word to highlight.
    String searchWord = "string";
    // Create a CharacterRange array with the searchWord 
    // location and length.
    CharacterRange ranges[] = new CharacterRange[] 
        { new CharacterRange(message.IndexOf(searchWord), 
        searchWord.get_Length()) };
    // Construct a StringFormat object.
    StringFormat stringFormat1 = new StringFormat();
    // Set the ranges on the StringFormat object.
    stringFormat1.SetMeasurableCharacterRanges(ranges);
    // Declare the font to write the message in.
    Font largeFont = new Font(FontFamily.get_GenericSansSerif(),
 
        16, GraphicsUnit.Pixel);
    // Construct a new Rectangle.
    Rectangle displayRectangle = new Rectangle(20, 20, 200, 100);
    // Convert the Rectangle to a RectangleF.
    RectangleF displayRectangleF = RectangleF.op_Implicit(displayRectangle);
    // Get the Region to highlight by calling the 
    // MeasureCharacterRanges method.
    Region charRegion[] = e.get_Graphics().MeasureCharacterRanges(message, 
        largeFont, displayRectangleF, stringFormat1);
    // Draw the message string on the form.
    e.get_Graphics().DrawString(message, largeFont, Brushes.get_Blue(),
        displayRectangleF);
    // Fill in the region using a semi-transparent color.
    e.get_Graphics().FillRegion(new SolidBrush(Color.FromArgb(50,
 
        Color.get_Fuchsia())), charRegion[0]);
    largeFont.Dispose();
} //HighlightACharacterRange
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「CharacterRange」の関連用語

CharacterRangeのお隣キーワード
検索ランキング

   

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



CharacterRangeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS