本文整理匯總了VB.NET中System.Drawing.Graphics.MeasureString方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Graphics.MeasureString方法的具體用法?VB.NET Graphics.MeasureString怎麽用?VB.NET Graphics.MeasureString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.MeasureString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MeasureStringMin
Private Sub MeasureStringMin(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Measure string.
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, stringFont)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
New PointF(0, 0))
End Sub
示例2: MeasureStringSizeF
Private Sub MeasureStringSizeF(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Set maximum layout size.
Dim layoutSize As New SizeF(200.0F, 50.0F)
' Measure string.
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, stringFont, _
layoutSize)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
New PointF(0, 0))
End Sub
示例3: MeasureStringWidth
Private Sub MeasureStringWidth(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Set maximum width of string.
Dim stringWidth As Integer = 200
' Measure string.
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, _
stringFont, stringWidth)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
New PointF(0, 0))
End Sub
示例4: MeasureStringPointFFormat
Private Sub MeasureStringPointFFormat(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Set point for upper-left corner of string.
Dim x As Single = 50.0F
Dim y As Single = 50.0F
Dim ulCorner As New PointF(x, y)
' Set string format.
Dim newStringFormat As New StringFormat
newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical
' Measure string.
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, stringFont, _
ulCorner, newStringFormat)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), x, y, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
ulCorner, newStringFormat)
End Sub
示例5: MeasureStringSizeFFormat
Private Sub MeasureStringSizeFFormat(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Set maximum layout size.
Dim layoutSize As New SizeF(100.0F, 200.0F)
' Set string format.
Dim newStringFormat As New StringFormat
newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical
' Measure string.
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, stringFont, _
layoutSize, newStringFormat)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
New PointF(0, 0), newStringFormat)
End Sub
示例6: MeasureStringWidthFormat
Private Sub MeasureStringWidthFormat(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Set maximum width of string.
Dim stringWidth As Integer = 100
' Set string format.
Dim newStringFormat As New StringFormat
newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical
' Measure string.
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, stringFont, _
stringWidth, newStringFormat)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
New PointF(0, 0), newStringFormat)
End Sub
示例7: MeasureStringSizeFFormatInts
Private Sub MeasureStringSizeFFormatInts(ByVal e As PaintEventArgs)
' Set up string.
Dim measureString As String = "Measure String"
Dim stringFont As New Font("Arial", 16)
' Set maximum layout size.
Dim layoutSize As New SizeF(100.0F, 200.0F)
' Set string format.
Dim newStringFormat As New StringFormat
newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical
' Measure string.
Dim charactersFitted As Integer
Dim linesFilled As Integer
Dim stringSize As New SizeF
stringSize = e.Graphics.MeasureString(measureString, stringFont, _
layoutSize, newStringFormat, charactersFitted, linesFilled)
' Draw rectangle representing size of string.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _
stringSize.Width, stringSize.Height)
' Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _
New PointF(0, 0), newStringFormat)
' Draw output parameters to screen.
Dim outString As String = "chars " & charactersFitted & _
", lines " & linesFilled
e.Graphics.DrawString(outString, stringFont, Brushes.Black, _
New PointF(100, 0))
End Sub
示例8: GraphicsMeasureString
' 導入命名空間
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