CharacterRange 구조체

정의

문자열 내의 문자 위치 범위를 지정합니다.

public value class CharacterRange : IEquatable<System::Drawing::CharacterRange>
public value class CharacterRange
public struct CharacterRange : IEquatable<System.Drawing.CharacterRange>
public struct CharacterRange
type CharacterRange = struct
Public Structure CharacterRange
Implements IEquatable(Of CharacterRange)
Public Structure CharacterRange
상속
CharacterRange
구현

예제

다음 코드 예제에서는 문자열의 일부를 만들고 CharacterRange 사용하여 강조 표시하는 방법을 보여 줍니다. 이 예제는 Windows Forms와 함께 사용하도록 설계되었습니다. 예제를 폼에 붙여넣고 폼의 HighlightACharacterRange 이벤트를 처리할 때 메서드를 호출 Paint 하여 다음과 같이 e전달 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

생성자

Name Description
CharacterRange(Int32, Int32)

문자열 내의 CharacterRange 문자 위치 범위를 지정하여 구조체의 새 인스턴스를 초기화합니다.

속성

Name Description
First

CharacterRange문자열의 첫 번째 문자에 있는 위치를 가져오거나 설정합니다.

Length

CharacterRange위치의 위치 수를 가져오거나 설정합니다.

메서드

Name Description
Equals(CharacterRange)

현재 인스턴스가 동일한 형식의 다른 인스턴스와 같은지 여부를 나타냅니다.

Equals(Object)

이 개체가 지정된 개체와 같은지 여부를 나타내는 값을 가져옵니다.

GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

연산자

Name Description
Equality(CharacterRange, CharacterRange)

CharacterRange 개체를 비교합니다. 두 First 개체의 Length 값이 CharacterRange 같은지 여부를 나타내는 값을 가져옵니다.

Inequality(CharacterRange, CharacterRange)

CharacterRange 개체를 비교합니다. 두 First 개체의 Length 값이 CharacterRange 같지 않은지 여부를 나타내는 값을 가져옵니다.

적용 대상