本文整理汇总了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