Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class DrawFontString
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
public class Form1
Inherits System.Windows.Forms.Form
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim blueBrush As New SolidBrush(Color.Blue)
Dim redBrush As New SolidBrush(Color.Red)
Dim greenBrush As New SolidBrush(Color.Green)
' Create a rectangle
Dim rect As New Rectangle(20, 20, 200, 100)
' The text to be drawn
Dim drawString As [String] = "Hello GDI+ World!"
' Create a Font
Dim drawFont As New Font("Verdana", 14)
Dim x As Single = 100.0F
Dim y As Single = 100.0F
' String format
Dim drawFormat As New StringFormat
' Set string format flag to direction vertical
' which draws text vertical
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
' Draw string
e.Graphics.DrawString("Drawing text", New Font("Tahoma", 14), greenBrush, rect.Location.X, rect.Location.Y)
e.Graphics.DrawString(drawString, New Font("Arial", 12), redBrush, 120, 140)
e.Graphics.DrawString(drawString, drawFont, blueBrush, x, y, drawFormat)
' Dispose
blueBrush.Dispose()
redBrush.Dispose()
greenBrush.Dispose()
drawFont.Dispose()
End Sub
Public Sub New()
MyBase.New()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
End Sub
End Class
|