Graphics.MeasureCharacterRanges メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Function MeasureCharacterRanges ( _ text As String, _ font As Font, _ layoutRect As RectangleF, _ stringFormat As StringFormat _ ) As Region()
Dim instance As Graphics Dim text As String Dim font As Font Dim layoutRect As RectangleF Dim stringFormat As StringFormat Dim returnValue As Region() returnValue = instance.MeasureCharacterRanges(text, font, layoutRect, stringFormat)
public Region[] MeasureCharacterRanges ( string text, Font font, RectangleF layoutRect, StringFormat stringFormat )
public: array<Region^>^ MeasureCharacterRanges ( String^ text, Font^ font, RectangleF layoutRect, StringFormat^ stringFormat )
public Region[] MeasureCharacterRanges ( String text, Font font, RectangleF layoutRect, StringFormat stringFormat )
public function MeasureCharacterRanges ( text : String, font : Font, layoutRect : RectangleF, stringFormat : StringFormat ) : Region[]
戻り値
このメソッドは、指定した文字列内の文字位置の範囲にそれぞれが外接する Region オブジェクトの配列を返します。


次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
赤の四角形が外接する最初の範囲 ("First") と、青の四角形が外接する 2 つ目の範囲 ("Second") が示された文字列が表示されます。
Public Sub MeasureCharacterRangesRegions(ByVal e As PaintEventArgs) ' Set up string. Dim measureString As String = "First and Second ranges" Dim stringFont As New Font("Times New Roman", 16.0F) ' Set character ranges to "First" and "Second". Dim characterRanges As CharacterRange() = _ {New CharacterRange(0, 5), New CharacterRange(10, 6)} ' Create rectangle for layout. Dim x As Single = 50.0F Dim y As Single = 50.0F Dim width As Single = 35.0F Dim height As Single = 200.0F Dim layoutRect As New RectangleF(x, y, width, height) ' Set string format. Dim stringFormat As New StringFormat stringFormat.FormatFlags = StringFormatFlags.DirectionVertical stringFormat.SetMeasurableCharacterRanges(characterRanges) ' Draw string to screen. e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _ x, y, stringFormat) ' Measure two ranges in string. Dim stringRegions(2) As [Region] stringRegions = e.Graphics.MeasureCharacterRanges(measureString, _ stringFont, layoutRect, stringFormat) ' Draw rectangle for first measured range. Dim measureRect1 As RectangleF = _ stringRegions(0).GetBounds(e.Graphics) e.Graphics.DrawRectangle(New Pen(Color.Red, 1), _ Rectangle.Round(measureRect1)) ' Draw rectangle for second measured range. Dim measureRect2 As RectangleF = _ stringRegions(1).GetBounds(e.Graphics) e.Graphics.DrawRectangle(New Pen(Color.Blue, 1), _ Rectangle.Round(measureRect2)) End Sub
public void MeasureCharacterRangesRegions(PaintEventArgs e) { // Set up string. string measureString = "First and Second ranges"; Font stringFont = new Font("Times New Roman", 16.0F); // Set character ranges to "First" and "Second". CharacterRange[] characterRanges = { new CharacterRange(0, 5), new CharacterRange(10, 6) }; // Create rectangle for layout. float x = 50.0F; float y = 50.0F; float width = 35.0F; float height = 200.0F; RectangleF layoutRect = new RectangleF(x, y, width, height); // Set string format. StringFormat stringFormat = new StringFormat(); stringFormat.FormatFlags = StringFormatFlags.DirectionVertical; stringFormat.SetMeasurableCharacterRanges(characterRanges); // Draw string to screen. e.Graphics.DrawString(measureString, stringFont, Brushes.Black, x, y, stringFormat); // Measure two ranges in string. Region[] stringRegions = new Region[2]; stringRegions = e.Graphics.MeasureCharacterRanges(measureString, stringFont, layoutRect, stringFormat); // Draw rectangle for first measured range. RectangleF measureRect1 = stringRegions[0].GetBounds(e.Graphics); e.Graphics.DrawRectangle(new Pen(Color.Red, 1), Rectangle.Round(measureRect1)); // Draw rectangle for second measured range. RectangleF measureRect2 = stringRegions[1].GetBounds(e.Graphics); e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), Rectangle.Round(measureRect2)); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGraphics.MeasureCharacterRanges メソッドを検索する場合は、下記のリンクをクリックしてください。

- Graphics.MeasureCharacterRanges メソッドのページへのリンク