CharacterRange CharacterRange CharacterRange CharacterRange Struct

定義

文字列内の文字位置の範囲を指定します。Specifies a range of character positions within a string.

public value class CharacterRange
public struct CharacterRange
type CharacterRange = struct
Public Structure CharacterRange
継承
CharacterRangeCharacterRangeCharacterRangeCharacterRange

次のコード例は、作成する方法を示します、CharacterRange文字列の一部を強調表示に使用します。The following code example demonstrates how to create a CharacterRange and use it to highlight part of a string. この例は、Windows フォームで使用する設計されています。This example is designed to be used with Windows Forms. 例では、エディターに貼り付け、フォームが呼び出し、HighlightACharacterRangeメソッド、フォームを処理するときにPaint渡すイベントeとしてPaintEventArgsします。Paste the example into a form and call the HighlightACharacterRange method when handling the form's Paint event, passing e as PaintEventArgs.

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.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();

}
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

コンストラクター

CharacterRange(Int32, Int32) CharacterRange(Int32, Int32) CharacterRange(Int32, Int32) CharacterRange(Int32, Int32)

CharacterRange 構造の新しいインスタンスを初期化して、文字列内の文字位置の範囲を指定します。Initializes a new instance of the CharacterRange structure, specifying a range of character positions within a string.

プロパティ

First First First First

この CharacterRange の、最初の文字の文字列の位置を取得または設定します。Gets or sets the position in the string of the first character of this CharacterRange.

Length Length Length Length

この CharacterRange 内の位置の数を取得または設定します。Gets or sets the number of positions in this CharacterRange.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このオブジェクトが指定されたオブジェクトと等しいかどうかを示す値を取得します。Gets a value indicating whether this object is equivalent to the specified object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このインスタンスのハッシュ コードを返します。Returns the hash code for this instance.

演算子

Equality(CharacterRange, CharacterRange) Equality(CharacterRange, CharacterRange) Equality(CharacterRange, CharacterRange) Equality(CharacterRange, CharacterRange)

2 つの CharacterRange オブジェクトを比較します。Compares two CharacterRange objects. 2 つの CharacterRange オブジェクトの First 値および Length 値が等しいかどうかを示す値を取得します。Gets a value indicating whether the First and Length values of the two CharacterRange objects are equal.

Inequality(CharacterRange, CharacterRange) Inequality(CharacterRange, CharacterRange) Inequality(CharacterRange, CharacterRange) Inequality(CharacterRange, CharacterRange)

2 つの CharacterRange オブジェクトを比較します。Compares two CharacterRange objects. 2 つの CharacterRange オブジェクトの First 値または Length 値が等しくないかどうかを示す値を取得します。Gets a value indicating whether the First or Length values of the two CharacterRange objects are not equal.

適用対象