' Art Example
' Use the Graphics object drawing methods to draw a picture.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents picDisplay As System.Windows.Forms.PictureBox
Private Sub InitializeComponent()
Me.picDisplay = New System.Windows.Forms.PictureBox
Me.SuspendLayout()
'
'picDisplay
'
Me.picDisplay.Location = New System.Drawing.Point(152, 112)
Me.picDisplay.Name = "picDisplay"
Me.picDisplay.Size = New System.Drawing.Size(104, 80)
Me.picDisplay.TabIndex = 0
Me.picDisplay.TabStop = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 342)
Me.Controls.Add(Me.picDisplay)
Me.Name = "Form1"
Me.Text = "Art Example"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
picDisplay.Location = New Point(0, 0)
picDisplay.Size = Me.ClientSize
Me.BackColor = Color.AliceBlue
End Sub
' Always resize picture box to fill maximum client
' area on form.
Private Sub Form1_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Resize
picDisplay.Location = New Point(0, 0)
picDisplay.Size = Me.ClientSize
End Sub
Private Sub picDisplay_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles picDisplay.Paint
' Set up pen and brushes.
Dim pen As New Pen(Color.Black, 2)
Dim blueBrush As New SolidBrush(Color.Blue)
Dim magentaBrush As New SolidBrush(Color.Magenta)
Dim maroonBrush As New SolidBrush(Color.Maroon)
Dim RedBrush As New SolidBrush(Color.FromArgb(255, 0, 90))
' Create arrays of points for polygons.
Dim array1() As Point = {New Point(50, 50), _
New Point(200, 50), New Point(100, 100), New Point(50, 200)}
Dim array2() As Point = {New Point(50, 250), _
New Point(200, 75), New Point(125, 125)}
' Get graphics context.
Dim g As Graphics = e.Graphics
' Draw shapes.
g.DrawPolygon(pen, array1)
g.DrawPolygon(pen, array2)
g.FillPolygon(blueBrush, array1)
g.FillPolygon(magentaBrush, array2)
g.DrawEllipse(pen, 250, 50, 50, 50)
g.FillEllipse(blueBrush, 250, 50, 50, 50)
g.DrawEllipse(pen, 200, 125, 100, 50)
g.FillEllipse(magentaBrush, 200, 125, 100, 50)
g.DrawEllipse(pen, 150, 200, 150, 50)
g.FillEllipse(maroonBrush, 150, 200, 150, 50)
' Draw String.
g.DrawString("VB.Net Art", New Font("Arial", 30, FontStyle.Bold), _
RedBrush, 35, 275)
End Sub
End Class