Graphics.MeasureString : Graphics « System.Drawing « VB.Net by API






Graphics.MeasureString

  


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Globalization


public class GraphicsMeasureString
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim g As Graphics = e.Graphics

        Dim s As String = "a multi-line string:" & vbCrLf & "line 2" & vbCrLf & "line 3"

        Dim layoutRect As RectangleF = RectangleF.op_Implicit(ClientRectangle)
        g.DrawString(s, Me.Font, Brushes.Black, layoutRect)
        Dim size As SizeF = g.MeasureString(s, Me.Font, layoutRect.Size)
        g.DrawRectangle(Pens.Black, 0, 0, size.Width, size.Height)

    End Sub


    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(20, 60)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    End Sub

End Class

   
    
  








Related examples in the same category

1.Graphics.DrawString
2.Graphics.Clear(Color c)
3.Graphics.Clip
4.Graphics.CompositingMode
5.Graphics.CompositingQuality
6.Graphics.DrawArc
7.Graphics.DrawBezier
8.Graphics.DrawClosedCurve
9.Graphics.DrawCurve
10.Graphics.DrawEllipse(Pen, Int x, Int y, Int w, Int h)
11.Graphics.DrawIcon
12.Graphics.DrawImage(Bitmap bmp, Int x, Int y)
13.Graphics.DrawLine(Pen p, Int x, Int y, Int x1, Int y1)
14.Graphics.DrawPath
15.Graphics.DrawPolygon
16.Graphics.DrawRectangle(Pen pen1, Rectangle rectangle1)
17.Graphics.DrawString(String s, Font m, Brush , Int x, Int y)
18.Graphics.ExcludeClip
19.Graphics.FillClosedCurve
20.Graphics.FillEllipse
21.Graphics.FillPath
22.Graphics.FillPie
23.Graphics.FillPolygon
24.Graphics.FillRectangle(Brush b, Rectangle rect)
25.Graphics.FromImage(Bitmap m)
26.Graphics.MeasureCharacterRanges
27.Graphics.PageUnit
28.Graphics.ResetTransform()
29.Graphics.Restore
30.Graphics.ScaleTransform
31.Graphics.SetClip(Shape shape,CombineMode)
32.Graphics.SmoothingMode
33.Graphics.TextRenderingHint
34.Graphics.Transform
35.Graphics.TranslateTransform