Share via


Metodo Graphics::MeasureCharacterRanges (gdiplusgraphics.h)

Il metodo Graphics::MeasureCharacterRanges ottiene un set di aree ognuna delle quali delimita un intervallo di posizioni di caratteri all'interno di una stringa.

Sintassi

Status MeasureCharacterRanges(
  [in]      const WCHAR        *string,
  [in]      INT                length,
  [in]      const Font         *font,
  [in, ref] const RectF &      layoutRect,
  [in]      const StringFormat *stringFormat,
  [in]      INT                regionCount,
  [out]     Region             *regions
);

Parametri

[in] string

Tipo: const WCHAR*

Puntatore a una stringa di caratteri wide.

Importante Per le lingue bidirezionali, ad esempio l'arabo, la lunghezza della stringa non deve superare i 2046 caratteri.
 

[in] length

Tipo: INT

Intero che specifica il numero di caratteri nella matrice di stringhe . Se il parametro stringa punta a una stringa con terminazione NULL, questo parametro può essere impostato su -1.

[in] font

Tipo: carattere const *

Puntatore a un oggetto Font che specifica le caratteristiche del carattere (il nome della famiglia, le dimensioni e lo stile del tipo di carattere) da applicare alla stringa.

[in, ref] layoutRect

Tipo: const Rectf

Riferimento a un rettangolo che delimita la stringa.

[in] stringFormat

Tipo: const StringFormat*

Puntatore a un oggetto StringFormat che specifica gli intervalli di caratteri e le informazioni sul layout, ad esempio allineamento, taglio, tabulazioni e così via.

[in] regionCount

Tipo: INT

Intero che specifica il numero di aree che devono essere ricevute nella matrice di aree . Questo numero deve essere uguale al numero di intervalli di caratteri attualmente presenti nell'oggetto StringFormat .

[out] regions

Tipo: Area geografica*

Puntatore a una matrice di oggetti Region che riceve le aree, ognuna delle quali delimita un intervallo di testo.

Valore restituito

Tipo: Stato

Se il metodo ha esito positivo, restituisce Ok, che è un elemento dell'enumerazione Status .

Se il metodo ha esito negativo, restituisce uno degli altri elementi dell'enumerazione Status .

Commenti

Un intervallo di caratteri è un intervallo di posizioni di caratteri all'interno di una stringa di testo. L'area della visualizzazione occupata da un gruppo di caratteri specificati dall'intervallo di caratteri è l'area di delimitazione. Un intervallo di caratteri viene impostato da SetMeasurableCharacterRanges. Il numero di intervalli attualmente impostati può essere determinato chiamando GetMeasurableCharacterRangeCount. Questo numero è anche il numero di aree che si prevede vengano ottenute dal metodo MeasureCharacterRanges .

Esempio

Nell'esempio seguente vengono definiti tre intervalli di posizioni di caratteri all'interno di una stringa e tali intervalli vengono impostati in un oggetto StringFormat . Viene quindi utilizzato il metodo MeasureCharacterRanges per ottenere le tre aree della visualizzazione occupate dai caratteri specificati dagli intervalli. Questa operazione viene eseguita per tre rettangoli di layout diversi per mostrare come le aree cambiano in base al layout della stringa. Inoltre, nella terza ripetizione di questo, i flag di formato stringa vengono modificati in modo che le aree misurate includano spazi finali.

VOID MeasureCharRanges(HDC hdc)
{
   Graphics graphics(hdc);

   // Brushes and pens used for drawing and painting
   SolidBrush blueBrush(Color(255, 0, 0, 255));
   SolidBrush redBrush(Color(100, 255, 0, 0));
   Pen        blackPen(Color(255, 0, 0, 0));

   // Layout rectangles used for drawing strings
   RectF   layoutRect_A(20.0f, 20.0f, 130.0f, 130.0f);
   RectF   layoutRect_B(160.0f, 20.0f, 165.0f, 130.0f);
   RectF   layoutRect_C(335.0f, 20.0f, 165.0f, 130.0f);

   // Three different ranges of character positions within the string
   CharacterRange charRanges[3] = { CharacterRange(3, 5),
                                    CharacterRange(15, 2),
                                    CharacterRange(30, 15), };

   // Font and string format to apply to string when drawing
   Font         myFont(L"Times New Roman", 16.0f);
   StringFormat strFormat;

    // Other variables
   Region* pCharRangeRegions; // pointer to CharacterRange regions
   short   i;                 // loop counter
   INT     count;             // number of character ranges set
   WCHAR   string[] = L"The quick, brown fox easily jumps over the lazy dog.";


   // Set three ranges of character positions.
   strFormat.SetMeasurableCharacterRanges(3, charRanges);

   // Get the number of ranges that have been set, and allocate memory to 
   // store the regions that correspond to the ranges.
   count = strFormat.GetMeasurableCharacterRangeCount();
   pCharRangeRegions = new Region[count];

   // Get the regions that correspond to the ranges within the string when
   // layout rectangle A is used. Then draw the string, and show the regions.
   graphics.MeasureCharacterRanges(string, -1,
      &myFont, layoutRect_A, &strFormat, count, pCharRangeRegions);
   graphics.DrawString(string, -1,
      &myFont, layoutRect_A, &strFormat, &blueBrush);
   graphics.DrawRectangle(&blackPen, layoutRect_A);
   for ( i = 0; i < count; i++)
   {
      graphics.FillRegion(&redBrush, pCharRangeRegions + i);
   }

   // Get the regions that correspond to the ranges within the string when
   // layout rectangle B is used. Then draw the string, and show the regions.
   graphics.MeasureCharacterRanges(string, -1,
      &myFont, layoutRect_B, &strFormat, count, pCharRangeRegions);
   graphics.DrawString(string, -1,
      &myFont, layoutRect_B, &strFormat, &blueBrush);
   graphics.DrawRectangle(&blackPen, layoutRect_B);
   for ( i = 0; i < count; i++)
   {
      graphics.FillRegion(&redBrush, pCharRangeRegions + i);
   }

   // Get the regions that correspond to the ranges within the string when
   // layout rectangle C is used. Set trailing spaces to be included in the
   // regions. Then draw the string, and show the regions.
   strFormat.SetFormatFlags(StringFormatFlagsMeasureTrailingSpaces);
   graphics.MeasureCharacterRanges(string, -1,
      &myFont, layoutRect_C, &strFormat, count, pCharRangeRegions);
   graphics.DrawString(string, -1,
      &myFont, layoutRect_C, &strFormat, &blueBrush);
   graphics.DrawRectangle(&blackPen, layoutRect_C);
   for ( i = 0; i < count; i++)
   {
      graphics.FillRegion(&redBrush, pCharRangeRegions + i);
   }
   // Delete memory for the range regions.
   delete [] pCharRangeRegions;
}

Requisiti

   
Client minimo supportato Windows XP, Windows 2000 Professional [solo app desktop]
Server minimo supportato Windows 2000 Server [solo app desktop]
Piattaforma di destinazione Windows
Intestazione gdiplusgraphics.h (include Gdiplus.h)
Libreria Gdiplus.lib
DLL Gdiplus.dll

Vedi anche

Characterrange

GetMeasurableCharacterRangeCount

Grafica

SetMeasurableCharacterRanges