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
|