Draw Coordinate : Coordinate « 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 » Coordinate 
15. 2. 1. Draw Coordinate
Draw Coordinate
 

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Drawing.Drawing2D

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

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private startPoint As New Point(50217)
    Private endPoint As New Point(50217)

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.SystemColors.Desktop
        Me.Button1.Location = New System.Drawing.Point(35216)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(9624)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Clear All"
        '
        'CheckBox1
        '
        Me.CheckBox1.Location = New System.Drawing.Point(35256)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.TabIndex = 1
        Me.CheckBox1.Text = "Rectangle"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.ClientSize = New System.Drawing.Size(480317)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.Button1)
        Me.Text = ""
        Me.ResumeLayout(False)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
        startPoint.X = 50
        startPoint.Y = 217
        endPoint.X = 50
        endPoint.Y = 217
        Me.Invalidate(Me.ClientRectangle)
    End Sub
    Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            Dim g1 As Graphics = Me.CreateGraphics()
            Dim linePen As New Pen(Color.Green, 1)
            Dim ellipsePen As New Pen(Color.Red, 1)
            startPoint = endPoint
            endPoint = New Point(e.X, e.Y)
            g1.DrawLine(linePen, startPoint, endPoint)
            If checkBox1.Checked Then
                g1.DrawRectangle(ellipsePen, e.X - 2, e.Y - 244)
            Else
                g1.DrawEllipse(ellipsePen, e.X - 2, e.Y - 244)
            End If
            linePen.Dispose()
            ellipsePen.Dispose()
            g1.Dispose()
        End If
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim As Graphics = e.Graphics
        Dim vertFont As New Font("Verdana"10, FontStyle.Bold)
        Dim horzFont As New Font("Verdana"10, FontStyle.Bold)
        Dim vertBrush As New SolidBrush(Color.Black)
        Dim horzBrush As New SolidBrush(Color.Blue)
        Dim blackPen As New Pen(Color.Black, 2)
        Dim bluePen As New Pen(Color.Blue, 2)
        ' Drawing a vertical and a horizontal line
        g.DrawLine(blackPen, 502205025)
        g.DrawLine(bluePen, 50220250220)
        'X axis drawing
        g.DrawString("0", horzFont, horzBrush, 30220)
        g.DrawString("1", horzFont, horzBrush, 50220)
        g.DrawString("2", horzFont, horzBrush, 70220)
        g.DrawString("3", horzFont, horzBrush, 90220)
        g.DrawString("4", horzFont, horzBrush, 110220)
        g.DrawString("5", horzFont, horzBrush, 130220)
        g.DrawString("6", horzFont, horzBrush, 150220)
        g.DrawString("7", horzFont, horzBrush, 170220)
        g.DrawString("8", horzFont, horzBrush, 190220)
        g.DrawString("9", horzFont, horzBrush, 210220)
        g.DrawString("10", horzFont, horzBrush, 230220)
        ' Drawing vertical strings
        Dim vertStrFormat As New StringFormat
        vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical

        g.DrawString("-", horzFont, horzBrush, 50212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 70212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 90212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 110212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 130212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 150212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 170212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 190212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 210212, vertStrFormat)
        g.DrawString("-", horzFont, horzBrush, 230212, vertStrFormat)
        'Y axis drawing
        g.DrawString("100-", vertFont, vertBrush, 2020)
        g.DrawString("90 -", vertFont, vertBrush, 2540)
        g.DrawString("80 -", vertFont, vertBrush, 2560)
        g.DrawString("70 -", vertFont, vertBrush, 2580)
        g.DrawString("60 -", vertFont, vertBrush, 25100)
        g.DrawString("50 -", vertFont, vertBrush, 25120)
        g.DrawString("40 -", vertFont, vertBrush, 25140)
        g.DrawString("30 -", vertFont, vertBrush, 25160)
        g.DrawString("20 -", vertFont, vertBrush, 25180)
        g.DrawString("10 -", vertFont, vertBrush, 25200)
        ' Dispose
        vertFont.Dispose()
        horzFont.Dispose()
        vertBrush.Dispose()
        horzBrush.Dispose()
        blackPen.Dispose()
        bluePen.Dispose()
    End Sub

End Class

        
15. 2. Coordinate
15. 2. 1. Draw CoordinateDraw Coordinate
15. 2. 2. GDI+ Coordinate SystemGDI+ Coordinate System
15. 2. 3. Draw line using integer coordinatesDraw line using integer coordinates
15. 2. 4. Draw line using float coordinatesDraw line using float coordinates
w_w___w_.ja___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.