StringFormat.SetMeasurableCharacterRanges(CharacterRange[]) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
MeasureCharacterRanges(String, Font, RectangleF, StringFormat) 메서드를 호출하여 측정한 문자 범위를 나타내는 CharacterRange 구조체의 배열을 지정합니다.
public:
void SetMeasurableCharacterRanges(cli::array <System::Drawing::CharacterRange> ^ ranges);
public void SetMeasurableCharacterRanges (System.Drawing.CharacterRange[] ranges);
member this.SetMeasurableCharacterRanges : System.Drawing.CharacterRange[] -> unit
Public Sub SetMeasurableCharacterRanges (ranges As CharacterRange())
매개 변수
- ranges
- CharacterRange[]
MeasureCharacterRanges(String, Font, RectangleF, StringFormat) 메서드를 호출하여 측정한 문자 범위를 지정하는 CharacterRange 구조체의 배열입니다.
예외
32개 보다 많은 문자 범위가 설정된 경우
예제
다음 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse
코드는 다음 작업을 수행합니다.
의 문자 범위를 StringFormat설정합니다.
지정된 문자열 및 레이아웃 사각형의 문자 범위를 측정합니다.
문자열 및 레이아웃 사각형을 그립니다.
영역을 그립니다. 각각 Region 은 문자 범위가 차지하는 영역을 지정합니다. 영역의 값은 메서드에 의해 MeasureCharacterRanges 문자 범위를 측정할 때 설정됩니다.
처음 네 단계를 반복하지만 각 문자 범위의 측정에 후행 공백이 포함됩니다.
후행 공백이 각 문자 범위의 StringFormat 측정값에 포함되지 않도록 의 형식 플래그를 지웁니다.
처음 네 단계를 반복하지만 레이아웃 사각형이 문자 범위의 측정값에 영향을 미치는지 보여주기 위해 다른 레이아웃 사각형을 사용합니다. 글꼴의 크기도 측정값에 영향을 미칩니다.
void SetMeasCharRangesExample( PaintEventArgs^ e )
{
Graphics^ g = e->Graphics;
SolidBrush^ redBrush = gcnew SolidBrush( Color::FromArgb( 50, 255, 0, 0 ) );
// Layout rectangles, font, and string format used for displaying string.
Rectangle layoutRectA = Rectangle(20,20,165,80);
Rectangle layoutRectB = Rectangle(20,110,165,80);
Rectangle layoutRectC = Rectangle(20,200,240,80);
System::Drawing::Font^ tnrFont = gcnew System::Drawing::Font( "Times New Roman",16 );
StringFormat^ strFormat = gcnew StringFormat;
// Ranges of character positions within a string.
array<CharacterRange>^ charRanges = {CharacterRange(3,5),CharacterRange(15,2),CharacterRange(30,15)};
// Each region specifies the area occupied by the characters within a
// range of positions. the values are obtained by using a method that
// measures the character ranges.
array<System::Drawing::Region^>^charRegions = gcnew array<System::Drawing::Region^>(charRanges->Length);
// String to be displayed.
String^ str = "The quick, brown fox easily jumps over the lazy dog.";
// Set the char ranges for the string format.
strFormat->SetMeasurableCharacterRanges( charRanges );
// loop counter (unsigned 8-bit integer)
Byte i;
// Measure the char ranges for a given string and layout rectangle. Each
// area occupied by the characters in a range is stored as a region. Then
// draw the string and layout rectangle, and paint the regions.
charRegions = g->MeasureCharacterRanges( str, tnrFont, layoutRectA, strFormat );
g->DrawString( str, tnrFont, Brushes::Blue, layoutRectA, strFormat );
g->DrawRectangle( Pens::Black, layoutRectA );
// Paint the regions.
for ( i = 0; i < charRegions->Length; i++ )
g->FillRegion( redBrush, charRegions[ i ] );
// Repeat the above steps, but include trailing spaces in the char
// range measurement by setting the appropriate string format flag.
strFormat->FormatFlags = StringFormatFlags::MeasureTrailingSpaces;
charRegions = g->MeasureCharacterRanges( str, tnrFont, layoutRectB, strFormat );
g->DrawString( str, tnrFont, Brushes::Blue, layoutRectB, strFormat );
g->DrawRectangle( Pens::Black, layoutRectB );
for ( i = 0; i < charRegions->Length; i++ )
g->FillRegion( redBrush, charRegions[ i ] );
// Clear all the format flags.
strFormat->FormatFlags = StringFormatFlags(0);
// Repeat the steps, but use a different layout rectangle. the dimensions
// of the layout rectangle and the size of the font both affect the
// character range measurement.
charRegions = g->MeasureCharacterRanges( str, tnrFont, layoutRectC, strFormat );
g->DrawString( str, tnrFont, Brushes::Blue, layoutRectC, strFormat );
g->DrawRectangle( Pens::Black, layoutRectC );
// Paint the regions.
for ( i = 0; i < charRegions->Length; i++ )
g->FillRegion( redBrush, charRegions[ i ] );
}
public void SetMeasCharRangesExample(PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush redBrush = new SolidBrush(Color.FromArgb(50, 255, 0, 0));
// Layout rectangles, font, and string format used for displaying string.
Rectangle layoutRectA = new Rectangle(20, 20, 165, 80);
Rectangle layoutRectB = new Rectangle(20, 110, 165, 80);
Rectangle layoutRectC = new Rectangle(20, 200, 240, 80);
Font tnrFont = new Font("Times New Roman", 16);
StringFormat strFormat = new StringFormat();
// Ranges of character positions within a string.
CharacterRange[] charRanges = { new CharacterRange(3, 5),
new CharacterRange(15, 2), new CharacterRange(30, 15)};
// Each region specifies the area occupied by the characters within a
// range of positions. the values are obtained by using a method that
// measures the character ranges.
Region[] charRegions = new Region[charRanges.Length];
// String to be displayed.
string str =
"The quick, brown fox easily jumps over the lazy dog.";
// Set the char ranges for the string format.
strFormat.SetMeasurableCharacterRanges(charRanges);
// loop counter (unsigned 8-bit integer)
byte i;
// Measure the char ranges for a given string and layout rectangle. Each
// area occupied by the characters in a range is stored as a region. Then
// draw the string and layout rectangle, and paint the regions.
charRegions = g.MeasureCharacterRanges(str, tnrFont,
layoutRectA, strFormat);
g.DrawString(str, tnrFont, Brushes.Blue, layoutRectA, strFormat);
g.DrawRectangle(Pens.Black, layoutRectA);
// Paint the regions.
for (i = 0; i < charRegions.Length; i++)
g.FillRegion(redBrush, charRegions[i]);
// Repeat the above steps, but include trailing spaces in the char
// range measurement by setting the appropriate string format flag.
strFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
charRegions = g.MeasureCharacterRanges(str, tnrFont,
layoutRectB, strFormat);
g.DrawString(str, tnrFont, Brushes.Blue, layoutRectB, strFormat);
g.DrawRectangle(Pens.Black, layoutRectB);
for (i = 0; i < charRegions.Length; i++)
g.FillRegion(redBrush, charRegions[i]);
// Clear all the format flags.
strFormat.FormatFlags = 0;
// Repeat the steps, but use a different layout rectangle. the dimensions
// of the layout rectangle and the size of the font both affect the
// character range measurement.
charRegions = g.MeasureCharacterRanges(str, tnrFont,
layoutRectC, strFormat);
g.DrawString(str, tnrFont, Brushes.Blue, layoutRectC, strFormat);
g.DrawRectangle(Pens.Black, layoutRectC);
// Paint the regions.
for (i = 0; i < charRegions.Length; i++)
g.FillRegion(redBrush, charRegions[i]);
}
Public Sub SetMeasCharRangesExample(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim redBrush As New SolidBrush(Color.FromArgb(50, 255, 0, 0))
' Layout rectangles, font, and string format used for
' displaying string.
Dim layoutRectA As New Rectangle(20, 20, 165, 80)
Dim layoutRectB As New Rectangle(20, 110, 165, 80)
Dim layoutRectC As New Rectangle(20, 200, 240, 80)
Dim tnrFont As New Font("Times New Roman", 16)
Dim strFormat As New StringFormat
' Ranges of character positions within a string.
Dim charRanges As CharacterRange() = {New CharacterRange(3, 5), _
New CharacterRange(15, 2), New CharacterRange(30, 15)}
' Each region specifies the area occupied by the characters within
' a range of positions. The values are obtained by using a method
' that measures the character ranges.
Dim charRegions(charRanges.Length) As [Region]
' String to be displayed.
Dim str As String = _
"The quick, brown fox easily jumps over the lazy dog."
' Set the char ranges for the string format.
strFormat.SetMeasurableCharacterRanges(charRanges)
' Loop counter (unsigned 8-bit integer).
Dim i As Byte
' Measure the char ranges for a given string and layout rectangle.
' Each area occupied by the characters in a range is stored as a
' region. then draw the string and layout rectangle and paint the
' regions.
charRegions = g.MeasureCharacterRanges(str, tnrFont, _
RectangleF.op_Implicit(layoutRectA), strFormat)
g.DrawString(str, tnrFont, Brushes.Blue, _
RectangleF.op_Implicit(layoutRectA), strFormat)
g.DrawRectangle(Pens.Black, layoutRectA)
' Paint the regions.
For i = 0 To charRegions.Length - 1
g.FillRegion(redBrush, charRegions(i))
Next i
' Repeat the above steps, but include trailing spaces in the char
' range measurement by setting the appropriate string format flag.
strFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces
charRegions = g.MeasureCharacterRanges(str, tnrFont, _
RectangleF.op_Implicit(layoutRectB), strFormat)
g.DrawString(str, tnrFont, Brushes.Blue, _
RectangleF.op_Implicit(layoutRectB), strFormat)
g.DrawRectangle(Pens.Black, layoutRectB)
' Paint the regions.
For i = 0 To charRegions.Length - 1
g.FillRegion(redBrush, charRegions(i))
Next i
' Clear all the format flags.
strFormat.FormatFlags = 0
' Repeat the steps, but use a different layout rectangle. The
' dimensions of the layout rectangle and the size of the font both
' affect the character range measurement.
charRegions = g.MeasureCharacterRanges(str, tnrFont, _
RectangleF.op_Implicit(layoutRectC), strFormat)
g.DrawString(str, tnrFont, Brushes.Blue, _
RectangleF.op_Implicit(layoutRectC), strFormat)
g.DrawRectangle(Pens.Black, layoutRectC)
' Paint the regions.
For i = 0 To charRegions.Length - 1
g.FillRegion(redBrush, charRegions(i))
Next i
End Sub
설명
32자 이상의 문자 범위를 설정하는 것은 허용되지 않으며 가 발생합니다 System.OverflowException.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기