Membuat Drawing Functions dengan VB.NET

Drawing Basic Shapes Vb.NET - Tutorial belajar visual basic net / vb.net kali ini tentang bagaimana cara membuat Drawing menggunakan vb.net khusus pemula, Sector code disini akan menjelaskan secara detail Penggunaan Drawing ini, pembelajaran ini dimulai dari membuat drawLine, DrawEllipse, DrawRectangle, DrawArc, DrawPolygon, DrawPie, DrawBezier.

Membuat DrawingVb.NET

Kita akan membuat project baru dengan nama "DrawingVbNet", desainlah tampilan form kamu kurang lebih hasilnya akan seperti gambar berikut :
Langsung saja kita membuat code untuk drawingnya ya..

DrawingLine VB.NET

Pada class form1 deklarasikan class drawing grapihics dan drawing pen yang nanti akan kita gunakan diseluruh button.
    Dim CreateGrapics As  _
System.Drawing.Graphics
Dim CreatePen As _
New System.Drawing.Pen(Color.Blue, 2)
Code DrawingLine
    Private Sub Button1_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button1.Click
Dim x1 As Integer = 10
Dim x2 As Integer = 80
Dim x3 As Integer = 280
Dim x4 As Integer = 80
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawLine(CreatePen, _
x1, x2, x3, x4)
End Sub

Code DrawEllipse

    Private Sub Button2_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button2.Click
Dim x1 As Integer = 50
Dim x2 As Integer = 50
Dim x3 As Integer = 100
Dim x4 As Integer = 150
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawEllipse(CreatePen, _
x1, x2, x3, x4)
End Sub

Code DrawRectangle

    Private Sub Button3_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button3.Click
Dim x1 As Integer = 30
Dim x2 As Integer = 30
Dim x3 As Integer = 50
Dim x4 As Integer = 60
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawRectangle(CreatePen, _
x1, x2, x3, x4)
End Sub

Code DrawArc

    Private Sub Button4_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button4.Click
Dim x1 As Integer = 20
Dim x2 As Integer = 20
Dim x3 As Integer = 100
Dim x4 As Integer = 100
Dim x5 As Integer = 150
Dim x6 As Integer = 160
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawArc(CreatePen, _
x1, x2, x3, x4, x5, x6)
End Sub

Code DrawPie

    Private Sub Button5_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button5.Click
Dim x1 As Integer = 50
Dim x2 As Integer = 50
Dim x3 As Integer = 150
Dim x4 As Integer = 150
Dim x5 As Integer = 0
Dim x6 As Integer = 170
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawPie(CreatePen, _
x1, x2, x3, x4, x5, x6)
End Sub

Code DrawPolygon

    Private Sub Button6_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button6.Click
Dim poly(5) As System.Drawing.Point
poly(0).X = 0
poly(0).Y = 0
poly(1).X = 53
poly(1).Y = 111
poly(2).X = 114
poly(2).Y = 86
poly(3).X = 34
poly(3).Y = 34
poly(4).X = 165
poly(4).Y = 7
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawPolygon(CreatePen, poly)
End Sub

Code DrawBezier

    Private Sub Button7_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button7.Click
Dim x1 As Integer = 100
Dim x2 As Integer = 200
Dim x3 As Integer = 240
Dim x4 As Integer = 250
Dim x5 As Integer = 100
Dim x6 As Integer = 200
Dim x7 As Integer = 150
Dim x8 As Integer = 30
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawBezier(CreatePen, _
100, 200, 240, 250, 100, 200, 150, 30)
End Sub
sedangkan untuk code aplikasi drawing functions keseluruhan silahkan lihat seluruh code berikut :
Public Class Form1
Dim CreateGrapics As _
System.Drawing.Graphics
Dim CreatePen As _
New System.Drawing.Pen(Color.Blue, 2)
Private Sub Button1_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button1.Click
Dim x1 As Integer = 10
Dim x2 As Integer = 80
Dim x3 As Integer = 280
Dim x4 As Integer = 80
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawLine(CreatePen, _
x1, x2, x3, x4)
End Sub

Private Sub Button2_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button2.Click
Dim x1 As Integer = 50
Dim x2 As Integer = 50
Dim x3 As Integer = 100
Dim x4 As Integer = 150
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawEllipse(CreatePen, _
x1, x2, x3, x4)
End Sub

Private Sub Button3_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button3.Click
Dim x1 As Integer = 30
Dim x2 As Integer = 30
Dim x3 As Integer = 50
Dim x4 As Integer = 60
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawRectangle(CreatePen, _
x1, x2, x3, x4)
End Sub

Private Sub Button4_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button4.Click
Dim x1 As Integer = 20
Dim x2 As Integer = 20
Dim x3 As Integer = 100
Dim x4 As Integer = 100
Dim x5 As Integer = 150
Dim x6 As Integer = 160
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawArc(CreatePen, _
x1, x2, x3, x4, x5, x6)
End Sub

Private Sub Button5_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button5.Click
Dim x1 As Integer = 50
Dim x2 As Integer = 50
Dim x3 As Integer = 150
Dim x4 As Integer = 150
Dim x5 As Integer = 0
Dim x6 As Integer = 170
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawPie(CreatePen, _
x1, x2, x3, x4, x5, x6)
End Sub

Private Sub Button6_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button6.Click
Dim poly(5) As System.Drawing.Point
poly(0).X = 0
poly(0).Y = 0
poly(1).X = 53
poly(1).Y = 111
poly(2).X = 114
poly(2).Y = 86
poly(3).X = 34
poly(3).Y = 34
poly(4).X = 165
poly(4).Y = 7
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawPolygon(CreatePen, poly)
End Sub

Private Sub Button7_Click(sender _
As System.Object, e As System.EventArgs) _
Handles Button7.Click
Dim x1 As Integer = 100
Dim x2 As Integer = 200
Dim x3 As Integer = 240
Dim x4 As Integer = 250
Dim x5 As Integer = 100
Dim x6 As Integer = 200
Dim x7 As Integer = 150
Dim x8 As Integer = 30
CreateGrapics = Me.CreateGraphics
CreateGrapics.DrawBezier(CreatePen, _
100, 200, 240, 250, 100, 200, 150, 30)
End Sub
End Class
Silahkan share jika bermanfaat.