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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
Imports System.Drawing.Drawing2D
Public Class Form3
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Pic1.Size = New Size(300, 150)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DrawPathString()
End Sub
Private Sub DrawPathString()
Using gr As Graphics = Pic1.CreateGraphics
gr.Clear(Pic1.BackColor)
gr.SmoothingMode = SmoothingMode.HighQuality
' Make the layout rect.
Dim layoutRect As New RectangleF(
5, 5,
Pic1.ClientRectangle.Width - 10,
Pic1.ClientRectangle.Height - 10)
' Make the Font.
Dim myfont As Font = New Font("Arial", 10.0, FontStyle.Bold, GraphicsUnit.Pixel)
' Make the String.
Dim s As String = "Outline Text"
' Make the StringFormat.
Dim fmt As StringFormat = New StringFormat
fmt.Alignment = StringAlignment.Center
fmt.LineAlignment = StringAlignment.Center
' Make the path string.
Dim path As New GraphicsPath
path.AddString(s,
myfont.FontFamily,
myfont.Style, myfont.Size,
New Point(0, 0), fmt)
' Make a transformation to map
' (xmin, ymin)-(xmax, ymax) onto
' the target area.
Dim pathRect As RectangleF = path.GetBounds()
Dim layoutPoints() As PointF = { _
New PointF(layoutRect.Left, layoutRect.Top),
New PointF(layoutRect.Right, layoutRect.Top),
New PointF(layoutRect.Left, layoutRect.Bottom)
}
gr.Transform = New Matrix(pathRect, layoutPoints)
Using textPen As New Pen(Brushes.Red, 0.0)
gr.DrawPath(textPen, path)
End Using
Using textBrush As New SolidBrush(Color.BlueViolet)
gr.FillPath(textBrush, path)
End Using
gr.ResetTransform()
gr.DrawRectangle(Pens.Green, Rectangle.Ceiling(layoutRect))
End Using
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DrawString()
End Sub
Private Sub DrawString()
Using gr As Graphics = Pic2.CreateGraphics
gr.Clear(Pic1.BackColor)
gr.SmoothingMode = SmoothingMode.HighQuality
' Make the layout rect.
Dim layoutRect As New RectangleF(
5, 5,
Pic1.ClientRectangle.Width - 10,
Pic1.ClientRectangle.Height - 10)
' Make the Font.
Dim myfont As Font = New Font("Arial", 10.0, FontStyle.Bold, GraphicsUnit.Pixel)
' Make the String.
Dim s As String = "Outline Text string"
' Make the StringFormat.
Dim fmt As StringFormat = New StringFormat
fmt.Alignment = StringAlignment.Center
fmt.LineAlignment = StringAlignment.Center
' Measure string
Dim sizeString As SizeF = gr.MeasureString(s, myfont, layoutRect.Width)
' Make a transformation to map
' (xmin, ymin)-(xmax, ymax) onto
' the target area.
Dim stringRect As RectangleF = New RectangleF(5, 5, sizeString.Width, sizeString.Height)
Dim layoutPoints() As PointF = { _
New PointF(layoutRect.Left, layoutRect.Top),
New PointF(layoutRect.Right, layoutRect.Top),
New PointF(layoutRect.Left, layoutRect.Bottom)
}
gr.Transform = New Matrix(stringRect, layoutPoints)
Using textBrush As New SolidBrush(Color.Red)
gr.DrawString(s, myfont, textBrush, stringRect, fmt)
End Using
gr.ResetTransform()
gr.DrawRectangle(Pens.Green, Rectangle.Ceiling(layoutRect))
End Using
End Sub
End Class |
Partager