1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
Public Class frmFont
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gr As Graphics = Me.CreateGraphics
Dim fnt As Font
Dim ss As SizeF
Dim S As String
Dim location As Point
Dim fmt As StringFormat = New StringFormat(StringFormat.GenericTypographic)
fmt.FormatFlags = StringFormatFlags.MeasureTrailingSpaces
'cas 1
S = " "
fnt = New Font("Garamond", 22, FontStyle.Bold)
ss = gr.MeasureString(S, fnt, 0, fmt)
' rectangle
location = New Point(100.0, 100.0)
Dim rect As New Rectangle(location.X, location.Y, ss.Width, ss.Height)
gr.DrawRectangle(New Pen(Color.Yellow, 1),
rect)
' string
gr.DrawString(S,
fnt,
Brushes.Black,
New RectangleF(location, ss), fmt)
'cas 2
S = " ".ToString
fnt = New Font("Garamond", 22, FontStyle.Bold)
ss = gr.MeasureString(S, fnt, 0, fmt)
' rectangle.
location = New Point(200.0, 200.0)
rect = New Rectangle(location.X, location.Y, ss.Width, ss.Height)
gr.DrawRectangle(New Pen(Color.DarkBlue, 1),
rect)
' string to screen.
gr.DrawString(S,
fnt,
Brushes.Black,
New RectangleF(location, ss), fmt)
End Sub
End Class |
Partager