Program yang dibahas kali ini terinspirasi dari program bawaan
Microsoft Windows yaitu Ms. Paint. Kali ini kita akan sedikit mengupas
cara membuat program paint tersebut dalam versi yang lebih sederhana
dengan menggunakan Visual Basic. Program ini dapat Anda download dan
kostumisasi sesuai keinginan Anda secara GRATIS.
Langkah pertama adalah membuat sebuah project dengan sebuah form
menggunakan objek label, button, picture box dan frame dengan desain
seperti ini:
Langkah selanjutnya adalah melakukan pengaturan properties sehingga tampilan didapat seperti pada gambar diatas.
Langkah terakhir adalah memberikan listing program untuk form tersebut sebagai berikut:
Dim paintnow As Boolean
Private Sub cmdhapus_Click()
cmdhapus.Enabled = False
cmdpensil.Enabled = True
End Sub
Private Sub cmdhpsemua_Click()
Picture1.Cls
End Sub
Private Sub cmdpensil_Click()
cmdpensil.Enabled = False
cmdhapus.Enabled = True
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 14
lblwarna(i).BackColor = QBColor(i)
Next i
Picture1.ForeColor = QBColor(0)
Picture1.BackColor = QBColor(15)
End Sub
Private Sub lblwarna_Click(Index As Integer)
Picture1.ForeColor = lblwarna(Index).BackColor
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
paintnow = True
Picture1.CurrentX = x
Picture1.CurrentY = y
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If paintnow Then
If cmdpensil.Enabled = False Then
Picture1.Line -(x, y), Picture1.ForeColor
Picture1.MousePointer = 99
End If
If cmdhapus.Enabled = False Then
Picture1.Line -(x, y), RGB(255, 255, 255), B
Picture1.MousePointer = 12
End If
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
paintnow = False
End If
End Sub
Private Sub cmdhapus_Click()
cmdhapus.Enabled = False
cmdpensil.Enabled = True
End Sub
Private Sub cmdhpsemua_Click()
Picture1.Cls
End Sub
Private Sub cmdpensil_Click()
cmdpensil.Enabled = False
cmdhapus.Enabled = True
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 14
lblwarna(i).BackColor = QBColor(i)
Next i
Picture1.ForeColor = QBColor(0)
Picture1.BackColor = QBColor(15)
End Sub
Private Sub lblwarna_Click(Index As Integer)
Picture1.ForeColor = lblwarna(Index).BackColor
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
paintnow = True
Picture1.CurrentX = x
Picture1.CurrentY = y
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If paintnow Then
If cmdpensil.Enabled = False Then
Picture1.Line -(x, y), Picture1.ForeColor
Picture1.MousePointer = 99
End If
If cmdhapus.Enabled = False Then
Picture1.Line -(x, y), RGB(255, 255, 255), B
Picture1.MousePointer = 12
End If
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
paintnow = False
End If
End Sub
Kemudian simpan dan jalankan program tersebut untuk melihat hasilnya.
Untuk mempermudah Anda mencoba program tersebut, berikut ini adalah Project lengkapnya yang sudah di upload dalam format rar:
Download Program Selengkapnyasumber : http://bangdanu.wordpress.com/2012/01/09/program-belajar-menulis-dan-menggambar-dengan-visual-basic/#more-805
owwwwwwwwwhhhhhhhhhhhh okeh punya ni artikel ...
ReplyDelete