Draw All Shapes : 2D Introduction « 2D Graphics « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » 2D Graphics » 2D Introduction 
15. 1. 1. Draw All Shapes
Draw All Shapes
 


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class DrawAllKindsOf
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Button7 As System.Windows.Forms.Button
    Friend WithEvents Button8 As System.Windows.Forms.Button
    Friend WithEvents Button9 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Button5 = New System.Windows.Forms.Button
        Me.Button6 = New System.Windows.Forms.Button
        Me.Button7 = New System.Windows.Forms.Button
        Me.Button8 = New System.Windows.Forms.Button
        Me.Button9 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.SystemColors.Window
        Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.PictureBox1.Location = New System.Drawing.Point(00)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(208266)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(2408)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(5624)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Dot"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(24048)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(5624)
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "Line"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(24088)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(5624)
        Me.Button3.TabIndex = 3
        Me.Button3.Text = "Ellipse"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(240128)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(5624)
        Me.Button4.TabIndex = 4
        Me.Button4.Text = "Arc"
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(240168)
        Me.Button5.Name = "Button5"
        Me.Button5.Size = New System.Drawing.Size(5624)
        Me.Button5.TabIndex = 5
        Me.Button5.Text = "Pie"
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(240208)
        Me.Button6.Name = "Button6"
        Me.Button6.Size = New System.Drawing.Size(5624)
        Me.Button6.TabIndex = 6
        Me.Button6.Text = "Rectangle"
        '
        'Button7
        '
        Me.Button7.Location = New System.Drawing.Point(3128)
        Me.Button7.Name = "Button7"
        Me.Button7.Size = New System.Drawing.Size(5624)
        Me.Button7.TabIndex = 7
        Me.Button7.Text = "Triangle"
        '
        'Button8
        '
        Me.Button8.Location = New System.Drawing.Point(31248)
        Me.Button8.Name = "Button8"
        Me.Button8.Size = New System.Drawing.Size(5624)
        Me.Button8.TabIndex = 8
        Me.Button8.Text = "Polygon"
        '
        'Button9
        '
        Me.Button9.Location = New System.Drawing.Point(31288)
        Me.Button9.Name = "Button9"
        Me.Button9.Size = New System.Drawing.Size(5624)
        Me.Button9.TabIndex = 9
        Me.Button9.Text = "Bezier Curve"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(376246)
        Me.Controls.Add(Me.Button9)
        Me.Controls.Add(Me.Button8)
        Me.Controls.Add(Me.Button7)
        Me.Controls.Add(Me.Button6)
        Me.Controls.Add(Me.Button5)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.PictureBox1)
        Me.ResumeLayout(False)

    End Sub

    Dim As System.Drawing.Graphics
    Dim pen1 As New System.Drawing.Pen(Color.Red, 3)
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
        PictureBox1.Refresh()
        g = PictureBox1.CreateGraphics
        Dim point1 As System.Drawing.Point
        Dim point2 As System.Drawing.Point
        point1.x = 10 
        point1.y = 20 

        point2.X = 11 
        point2.Y = 21
        g.DrawLine(pen1, point1, point2)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button2.Click
        g = PictureBox1.CreateGraphics
        g.DrawLine(pen1, 2020160160)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button3.Click
        g = PictureBox1.CreateGraphics
        g.DrawEllipse(pen1, 5050100150)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button4.Click
        g = PictureBox1.CreateGraphics
        g.DrawArc(pen1, 9050100150150160)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button5.Click
        g = PictureBox1.CreateGraphics
        g.DrawPie(pen1, 50501501500170)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button6.Click
        g = PictureBox1.CreateGraphics
        g.DrawRectangle(pen1, 30305060)
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button7.Click
        Dim p(3As System.Drawing.Point
        p(0).X = 0
        p(0).Y = 0
        p(1).X = 40
        p(1).Y = 120
        p(2).X = 110
        p(2).Y = 70
        g = PictureBox1.CreateGraphics
        g.DrawPolygon(pen1, p)
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button8.Click
        Dim p(5As System.Drawing.Point
        p(0).X = 0
        p(0).Y = 0
        p(1).X = 40
        p(1).Y = 120
        p(2).X = 110
        p(2).Y = 70
        p(3).X = 30
        p(3).Y = 30
        p(4).X = 170
        p(4).Y = 10
        g = PictureBox1.CreateGraphics
        g.DrawPolygon(pen1, p)
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button9.Click
        g = PictureBox1.CreateGraphics
        g.DrawBezier(pen1, 102014015010030150200)
    End Sub
End Class

        
15. 1. 2D Introduction
15. 1. 1. Draw All ShapesDraw All Shapes
w___w_w.__j__a__v_a__2_s.___c_o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.