Ler em inglês

Partilhar via


CharacterRange Estrutura

Definição

Especifica um intervalo de posições de caractere em uma cadeia de caracteres.

C#
public struct CharacterRange
C#
public struct CharacterRange : IEquatable<System.Drawing.CharacterRange>
Herança
CharacterRange
Implementações

Exemplos

O exemplo de código a seguir demonstra como criar um CharacterRange e usá-lo para realçar parte de uma cadeia de caracteres. Este exemplo foi projetado para ser usado com Windows Forms. Cole o exemplo em um formulário e chame o HighlightACharacterRange método ao manipular o evento do Paint formulário, passando e como PaintEventArgs.

C#
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();
}

Construtores

CharacterRange(Int32, Int32)

Inicializa uma nova instância da estrutura CharacterRange, especificando um intervalo de posições de caracteres em uma cadeia de caracteres.

Propriedades

First

Obtém ou define a posição na cadeia de caracteres do primeiro caractere deste CharacterRange.

Length

Obtém ou define o número de posições neste CharacterRange.

Métodos

Equals(CharacterRange)

Indica se a instância atual é igual a outra instância do mesmo tipo.

Equals(Object)

Obtém um valor que indica se esse objeto é equivalente ao objeto especificado.

GetHashCode()

Retorna o código hash para a instância.

Operadores

Equality(CharacterRange, CharacterRange)

Compara dois objetos CharacterRange. Obtém um valor que indica se os valores de First e Length dos dois objetos CharacterRange são iguais.

Inequality(CharacterRange, CharacterRange)

Compara dois objetos CharacterRange. Obtém um valor que indica se os valores de First ou Length dos dois objetos CharacterRange não são iguais.

Aplica-se a

Produto Versões
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9