Pemrogaman Visual Basic.NET (Modul 2)
-
Upload
materi-kuliah-online -
Category
Education
-
view
1.678 -
download
3
Transcript of Pemrogaman Visual Basic.NET (Modul 2)
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 1
Pemrograman Form pada VB.Net
Oleh : Hendra, ST.
Buku ini membahas tentang pembuatan program Windows Form dengan bahasa
pemrograman Visual Basic .Net, dan ditujukan kepada siapa saja yang serius untuk
mempelajari pembuatan form dan control dengan VB.NET secara koding (tanpa
menggunakan fasilitas designer pada Visual Studio .NET). Bagi anda yang belum
mengenal bahasa pemrograman VB.NET sebaiknya memulai proses belajar dengan buku
Bahasa Pemrograman VB.NET.
Untuk mempelajari buku ini anda tidak perlu menginstalasi Visual Studio .NET, tetapi
anda cukup menginstalasi .Net Framework yang dapat didownload secara gratis dari
website Microsoft.
Semua contoh dan latihan dibuku ini dapat dikompilasi langsung dari Dos prompt dengan
menggunakan kompiler Visual Basic yang langsung tersedia setelah anda menginstalasi
.Net Framework.
Dibandingkan dengan Visual Basic 6.0, maka VB.NET adalah benar-benar bahasa
pemrograman, dimana pembuatan form dan control dapat dilakukan secara koding 100%,
sedangkan pada Visual Basic 6.0 hal tersebut tidak dimungkinkan.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 2
Program Windows Form
Windows Forms merupakan platform pada .NET Framework untuk pengembangan
program aplikasi yang berbasis Form pada Windows. Framework ini menyediakan
berbagai class-class yang jelas, berorientasi objek, dan dapat dikembangkan, Windows
Forms dapat bertindak sebagai interface local pada solusi client server maupun multi-tier
terdistribusi.
Catatan :
Pada VB.NET, kita dapat melakukan pemrograman form tanpa menggunakan fasilitas
designer sama sekali dan tentu saja cara ini cukup menyulitkan bagi programmer VB
yang sudah terbiasa menggunakan IDE.
Sebenarnya fasilitas IDE berbasis .NET dapat diperoleh dengan menginstalasi Visual
Studio.NET, dan tentu saja membutuhkan suatu investasi yang besar untuk mempelajari
bahasa pemrograman ini bagi mahasiswa maupun kalangan perguruan tinggi.
Tutorial ini menggunakan pendekatan koding langsung yang dapat dilakukan dengan
notepad maupun edit, dan hasil koding dapat dikompilasi dengan compiler Visual Basic
yang tersedia begitu kita menginstalasi Microsoft .NET Framework yang dapat
didownload gratis di situs Microsoft.
Penulis yakin proses pembelajaran dengan pendekatan koding merupakan langkah yang
sangat tepat untuk membawa anda menjadi professional yang menguasai VB.NET secara
mendalam dan mengendalikan secara penuh program aplikasi anda.
Apa itu form ?
Form merupakan interface antara program dengan pemakai untuk proses input output.
Pada Windows, form dapat berupa :
• single-document interface (SDI)
• multiple-document interface (MDI)
• Explorer-style interface
Salah satu contoh dari interface SDI adalah aplikasi WordPad.
Adapun program aplikasi Windows yang berbasis pada form yang paling sederhana
adalah :
Option Explicit On Imports System Public Module MyModule
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 3
Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Belajar Buat Form" 'untuk title form Form1.ShowDialog() 'form modal End Sub
End Module
Proses Kompilasi
Kemudian simpan dengan nama form.vb anda dapat melakukan kompilasi dengan
perintah :
Vbc <namafile> /r:System.dll /r:System.Windows.Forms.dll /r:System.Drawing.dll
Contoh :
Vbc form.vb /r:System.dll /r:System.Windows.Forms.dll
Selanjutnya anda dapat menjalankannya sebagaimana program Windows dan
menghasilkan tampilan berikut :
Membuat Form senantiasa diatas form lain
Form yang senantiasa berada diatas form lain maksudnya adalah form yang tidak dapat
ditimpa oleh form lain diatas layar. Form-form sejenis ini biasanya digunakan pada
aplikasi screen saver maupun aplikasi security untuk mengunci layar seperti pada Billing
System pada warna, maupun program pada Front Desk, maupun POS untuk mencegah
pemakai beralih ke layar lain. Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini senantiasa diatas form lainnya" Form1.TopMost = True Form1.ShowDialog() End Sub End Module
Membuat Form transparan
Kita dapat menggunakan properties Opacity yang dapat diset antara nilai double 0.0
(paling transparan) s/d 1.0
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 4
Option Explicit On Imports System Imports System.Threading Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini akan semakin transparan" Form1.Show() For I As Double = 1 To 0 Step -0.01 Form1.Opacity = I Form1.Refresh() 'refresh form dengan setting baru Thread.Sleep(100) 'memperlambat program 100 millidetik Next I End Sub End Module
Menampilkan Form Modal dan Modeless
Form Modal harus ditutup atau hidden sebelum program berikutnya dijalankan,
sedangkan pada Modeless program akan dilanjutkan setelah form ditampilkan. Biasanya
form Modal digunakan untuk menampilkan dialog box yang membutuhkan perhatian
pemakai dan proses tidak boleh dialihkan sebelum mendapatkan keputusan dari pemakai.
Untuk form Modal dapat digunakan metoda ShowDialog(), sedangkan untuk form
Modeless dapat digunakan metoda Show().
Mengatur border pada form
Ada beberapa model border yang dapat diset pada properti FormBorderStyle, berikut ini
adalah beberapa enumerasi pada FormBorderStyle.
Setting Description
None Tidak ada border, biasanya digunakan untuk splash screen
Fixed3D Menggunakan efek tiga dimensi. Ukuran form tidak dapat diubah. Dapat diikuti oleh tombol control-menu box, title bar, Maximize dan Minimize pada title bar.
FixedDialog Digunakan untuk fixedDialog
FixedSingle Tidak dapat diubah ukurannya
FixedToolWindow Digunakan untuk tool windows, dan form tidak ditampilkan pada task bar
Sizable Form default
SizableToolWindow Tools windows yang dapat diubah ukurannya
Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 5
Sub Main() Form1.Text = "Form ini menggunakan border fixed 3D" Form1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog Form1.ShowDialog() End Sub End Module
Kita dapat juga mengatur keberadaan button maximize dan minimize, dengan properti
MinimizeBox dan MaximizeBox, contoh :
Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini tanpa tombol Maximize dan Minimize" Form1.MinimizeBox = False Form1.MaximizeBox = False Form1.ShowDialog() End Sub End Module
Mengatur ukuran form
Untuk mengubah ukuran form pada saat runtime dapat menggunakan properti Height,
dan Width, misalnya kita ingin mengubah ukuran form menjadi 500 x 500 pixel, Contoh :
Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini berukuran 500 x 500 pixel" Form1.Width = 500 Form1.Height = 500 Form1.ShowDialog() End Sub End Module Catatan :
Jika kita tidak menentukan ukuran form, maka default suatu form adalah 300 x 300 pixel
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 6
Ukuran form juga tergantung pada setting properti WindowState, yang mana dapat diset
dengan enumerasi dari FormWindowState berikut :
Member name Description
Maximized Jendela maximized.
Minimized Jendela minimize
Normal Jendela default
Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini dalam state Maximize" Form1.WindowState = System.Windows.Forms.FormWindowState.Maximized Form1.ShowDialog() End Sub End Module
Mengatur lokasi form di layar
Untuk menentukan posisi form dilayar dapat digunakan properti Left, dan Top, serta
StartPosition, contoh: Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini berada di posisi 0,0" Form1.Top = 0 Form1.Left = 0 Form1.ShowDialog() End Sub End Module Sedangkankan untuk pemakaian properti StartPosition kita dapat menggunakan enumerasi FormStartPosition sebagai berikut : Member name Description
CenterParent The form is centered within the bounds of its parent form.
CenterScreen The form is centered on the current display, and has the dimensions specified in the form's size.
Manual The position of the form is determined by the Location property.
WindowsDefaultBounds The form is positioned at the Windows default location and has the bounds
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 7
determined by Windows default.
WindowsDefaultLocation The form is positioned at the Windows default location and has the dimensions specified in the form's size.
Contoh : Option Explicit On Imports System Public Module MyModule Dim Form1 As New System.Windows.Forms.Form Sub Main() Form1.Text = "Form ini berada ditengah layar" Form1.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Form1.ShowDialog() End Sub End Module
Latihan :
Buatlah program aplikasi windows yang dapatkan menampilkan form dengan ketentuan
sebagai berikut :
1. Judul Form : Form saya yang pertama
2. Ukuran : 450 x 450 pixel
3. Berada diposisi : 200,200
4. Bingkai : Fixed Single
5. Opacity : 0.5
Modifikasi program diatas untuk menampilkan form tersebut ditengah layar.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 8
OOP pada program Windows Form
Adapun teknik lain yang dapat digunakan untuk pembuatan program Windows Form
adalah dengan pendekatan OOP, dimana kita membangun class baru yang di inherit dari
System.Windows.Forms.Form, contoh :
Option Explicit On Imports System Public Class MyForm Inherits System.Windows.Forms.Form <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub End Class
Pada program sebelumnya, kita senantiasa menggunakan Form1.ShowDialog() untuk
menampilkan Form1 secara modal, sedangkan kalau kita menggunakan Form1.Show(),
form hanya ditampilkan sebentar kemudian hilang karena program aplikasi kita segera
berakhir sesaat setelah Form1 ditampilkan, dan konsekuensinya Form1 juga dibuang dari
memori.
Sedangkan perintah System.Windows.Forms.Application.Run(New MyForm), akan
mengatur message dari sistem operasi ke program aplikasi, jika program anda tidak
mencantumkan baris ini, maka program dapat dikompilasi dan dijalankan tanpa
menghasilkan apa-apa.
Catatan :
Inheritance adalah salah satu ciri-ciri dari pemrograman berorientasi objek. Sebagaimana
kita ketahui bahwa Class Form telah tersedia pada .NET terdefinisi pada namespace
System.Windows.Forms.
Selanjutnya jika kita membuat class baru dengan melakukan inherit dari class Form,
maka secara otomatis akan mewarisi semua property, metoda, dan event yang sifatnya
protected dan public pada class Form.
Jadi kita tidak perlu perlu menulis ulang semua prilaku pada class baru, melainkan cukup
melakukan inherit dari parent class yang secara otomatis akan mewariskan semua
prilakunya ke child class.
Inheritance
Salah satu keunggulan dari OOP adalah isu pemanfaatan kembali. Dengan inheritance
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 9
tugas pemrograman dapat dipemudah. Suatu class yang telah dikembangkan dapat
diperbaharui dengan mengembangkan child class (sub class) yang merupakan inheritance
dari parent class (super class).
Inheritance menyerupai pengembangan produk baru pada suatu perusahaan, dimana
engineer tidak perlu membuat produk baru dari awal, tetapi dengan mengacu pada produk
yang telah ada, dan dilakukan penambahan dan perbaikan.
Mengatur setting Form dengan Constructor
Untuk pengaturan setting Form, kita dapat membuat suatu Constructor bagi Class
MyForm. Constructor adalah metoda khusus suatu Class yang akan otomatis dijalankan
begitu instance dari Class dibuat dimemori komputer.
Catatan :
Perintah New MyForm adalah membuat instance dari Class MyForm. Dalam OOP istilah
Class sering dicampuradukan dengan Objek, pada hal sebenarnya Class merupakan cetak
biru dari Objek.
Hubungan antara Object dan Class
Object merupakan instance dari Class, beberapa object dapat berasal dari Class yang
sama, tetapi memiliki properti yang berbeda-beda (dengan bahasa yang lebih sederhana
dapat dikatakan bahwa class merupakan blue print dari objek-objek).
Misalnya dalam membangun rumah, maka sebelumnya dilakukan rancangan awal dengan
mengambarkan detail dari rumah serta ukuran-ukurannya, kemudian oleh pengembang
akan dibangun rumah-rumah yang nyata berdasarkan blue print tersebut.
Pada pembuatan program OOP, dimulai dengan pembuatan Class, dan pada saat runtime
akan dibuat instance dari Class sebagai Objek, jadi program tersebut berjalan sebagai
objek-objek dimemori komputer.
Pada Visual Basic, constructor untuk suatu Class ciptaan dapat menggunakan Public Sub
New. Contoh :
Option Explicit On Imports System
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 10
Public Class MyForm Inherits System.Windows.Forms.Form <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub Public Sub New() 'Constructor Me.Text = "Dengan pendekatan OOP" End Sub End Class
Catatan :
Konstruktor merupakan metode khusus pada class, dimana metoda ini otomatis akan
dijalankan oleh computer sesaat instance dari class dibuat, misalnya (New MyForm):
System.Windows.Forms.Application.Run(New MyForm)
Pada dunia nyata, setiap objek mengalami kelahiran dan kematian, contoh sebuah rumah
mengalai tahap pembuatan (pembangunan) dan akhirnya akan diruntuhkan demikian juga
manusia juga mengalami kelahiran dan kematian, pada saat seorang bagi dilahirkan,
maka akan membawa property seperti jenis kelamin, berat badan, dan panjang.
Sebagaimana objek pada dunia nyata, objek dikomputer pada saat dibuat, tentu saja ada
property-properti tertentu yang perlu disetting nilai awalnya, dan hal tersebut dapat
dilakukan dengan membuat konstruktor untuk class tersebut.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 11
Penanganan Event pada form
Salah satu ciri dari pemrograman pada windows adalah bagaimana menangani event yang
dibangkitan oleh sistem operasi dan aplikasi berdasarkan aksi yang dilakukan oleh
pemakai terhadap form, misalnya melakukan klik pada mouse, ataupun penekanan
tombol.
Event pada Form Event Terjadi pada saat Argumen
Activated Terjadi ketika form diaktifkan EventHandle
GotFocus Terjadi ketika kontrol mendapatkan focus EventHandle
Load Terjadi ketika form ditampilkan untuk pertama kali EventHandle
Resize Terjadi ketika kontrol mengalami perubahan ukuran EventHandle
Move Terjadi ketika kontrol berpindah EventHandle
LostFocus Terjadi ketika kontrol kehilangan fokus EventHandle
Closing Terjadi ketika form akan ditutup CancelEventHandle
Closed Terjadi ketika form ditutup EventHandle
Deactivate Terjadi ketika form kehilangan keaktifan EventHandle
Catatan :
Penanganan Event menjadi salah satu permasalahan yang dihadapi pemrograman yang
mengembangkan aplikasi mereka di lingkungan Windows, sebagaimana kita ketahui
bahwa Windows merupakan system operasi multitasking yang mana komunikasi antara
program aplikasi dengan system operasi dilakukan berdasarkan message.
Pada lingkungan multitasking, berbagai aksi yang dilakukan oleh pemakai pada system
operasi dapat mempengaruhi proses pada program kita, seperti klik pada mouse,
penekanan pada tombol.
Jika anda berasal dari pemrograman lingkungan DOS yang mana proses program berjalan
berdasarkan alur yang kita buat dari baris awal sampai baris terakhir, tentu saja akan
mengalami kesulitan untuk beralih ke pemrograman Windows dengan cepat, sebab
program di Windows berjalan berdasarkan Event. Tetapi saya yakin dengan latihan yang
intensif anda dapat dengan segera menyesuaikan diri.
System.EventHandle
Adapun tata cara penulisan event procedure untuk event yang menggunakan EventHandle
adalahs sebagai berikut :
Private Sub NamaKontrol_NamaEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.NamaEvent
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 12
System.ComponentModel.CancelEventArgs
Private Sub Form_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Pada CancelEventArgs tersedia properti Cancel yang dapat diset ke nilai True/False
dengan tujuan proses Closing dilanjutkan atau dibatalkan.
Contoh :
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form Dim CatatEvent As String <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub Public Sub New() 'Constructor Me.Text = "Mencoba Event pada Form" End Sub Private Sub MyForm_Load(sender as Object, e As System.EventArgs) Handles MyBase.Load CatatEvent = "Terjadi Load" & vbCrlf End Sub Private Sub MyForm_Activated(sender as Object, e As System.EventArgs) Handles MyBase.Activated CatatEvent = CatatEvent & "Terjadi Activate" & vbCrlf End Sub Private Sub MyForm_GotFocus(sender as Object, e As System.EventArgs) Handles MyBase.GotFocus CatatEvent = CatatEvent & "Terjadi GotFocus" & vbcrlf End Sub Private Sub MyForm_Move(sender as Object, e As System.EventArgs) Handles MyBase.Move CatatEvent = CatatEvent & "Terjadi Move" & vbcrlf End Sub Private Sub MyForm_Resize(sender as Object, e As System.EventArgs) Handles MyBase.Resize CatatEvent = CatatEvent & "Terjadi Resize" & vbcrlf End Sub Private Sub MyForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 13
CatatEvent = CatatEvent & "Terjadi Closing" & vbCrlf e.Cancel = False End Sub Private Sub MyForm_Deactivate(sender as Object, e As System.EventArgs) Handles MyBase.Deactivate CatatEvent = CatatEvent & "Terjadi Deactivate" & vbCrlf Msgbox(CatatEvent) End Sub Private Sub MyForm_LostFocus(sender as Object, e As System.EventArgs) Handles MyBase.LostFocus CatatEvent = CatatEvent & "Terjadi LostFocus" & vbCrlf End Sub Private Sub MyForm_Closed(sender as Object, e As System.EventArgs) Handles MyBase.Closed CatatEvent = CatatEvent & "Terjadi Closed" & vbCrlf End Sub End Class
Dimana kalau program dijalankan dan kemudian ditutup akan menampilkan kotak pesan
yang berisi urutan event yang terjadi pada form mulai dari program dijalankan sampai
ditutup.
Event pada Mouse
Event pada Mouse dibangkitkan pada saat pemakai melakukan aktifitas mouse terhadap
form. Sesuai dengan urutan kejadiaannya adalah sebagai berikut :
Event Terjadi pada saat Argumen
MouseEnter mouse pointer memasuki control EventHandle
MouseMove mouse pointer bergerak diatas control MouseEventHandle
MouseHover mouse pointer melewati control EventHandle
MouseDown penekanan button mouse diatas control MouseEventHandle
MouseWheel pergerakan wheel pada mouse diatas control yang sedang focus MouseEventHandle
Click Klik pada control EventHandle
DoubleClick Double klik pada control EventHandle
MouseUp pelepasan button mouse diatas control MouseEventHandle
MouseLeave Mouse meninggalkan control EventHandle
Dalam tata cara penulisan event procedure untuk event mouse terbagi atas dua jenis
argumen yang dikirim ke procedure, yaitu EventHandle, dan MouseEventHandle.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 14
System.EventHandle
Adapun tata cara penulisan event procedure untuk event yang menggunakan EventHandle
adalahs sebagai berikut :
Private Sub NamaKontrol_NamaEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.NamaEvent
Contoh :
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.EnableVisualStyles() System.Windows.Forms.Application.Run(New MyForm) End Sub Public Sub New() 'Constructor Me.Text = "Dengan pendekatan OOP" End Sub Private Sub MyForm_MouseEnter(sender as Object, e As System.EventArgs) Handles MyBase.MouseEnter Msgbox("Terjadi Event MouseEnter") End Sub
End Class
System.Windows.Forms.Form.MouseEventHandle
Adapun tata cara penulisan event procedure untuk event yang menggunakan
MouseEventHandle adalah sebagai berikut : Private Sub NamaKontrol_NamaEvent(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.NamaEvent
Informasi yang dapat diperoleh dari MouseEventHandle :
Property Description
Button Mendapatkan tombol mouse yang ditekan (None, Left, Middle, Right, Xbutton1, Xbutton2)
Clicks Mendapatkan jumlah klik
Delta Mendapatkan jumlah rotasi roda mouse
X Mendapatkan koordinat X mouse
Y Mendapatkan koordinat Y mouse
Contoh :
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 15
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.EnableVisualStyles() System.Windows.Forms.Application.Run(New MyForm) End Sub Public Sub New() 'Constructor Me.Text = "Dengan pendekatan OOP" End Sub Private Sub MyForm_MouseDown(sender as Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown Msgbox("Terjadi Event MouseDown pada " & e.x.tostring() & "," &e.y.tostring()) End Sub
End Class
Kalau kita menekan button mouse diatas MyForm, maka msgbox berikut akan
ditampilkan.
Event pada Keyboard
Event pada keyboard terjadi pada saat pemakaian melakukan aksi penekanan tombol
terhadap form, dan urutan event keyboard adalah sebagai berikut :
Event Terjadi pada saat Argumen
KeyDown Tombol ditekan ke bawah KeyEventHandle
KeyPressed Tombol ditekan KeyPressEventHandle
KeyUp Tombol dilepas KeyEventHandle
System.Windows.Forms.KeyEventHandle
Adapun tata cara penulisan event procedure untuk event yang menggunakan
KeyEventHandle adalah sebagai berikut :
Private Sub NamaKontrol_NamaEvent(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.NamaEvent
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 16
Informasi yang dapat diperoleh dari KeyEventArgs
Property Description
Alt Mendapatkan apakah tombol ALT ada ditekan atau tidak
Control Mendapatkan apakah tombol CTRL ada ditekan atau tidak
Handled Mendapatkan apakah event telah terhandle
KeyCode Mendapatkan key code
KeyData Mendapatkan key data
KeyValue Mendapatkan keybiard value
Modifiers Medapatkan flag modifier apakah event mouse disertai dengan kombinasi tombol (CTRL, SHIFT, and ALT)
Shift Mendapatkan apakah tombol shift ditekan
Contoh :
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub Public Sub New() 'Constructor Me.Text = "Dengan pendekatan OOP" End Sub Private Sub MyForm_KeyDown(sender as Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown Msgbox("Nilai Alt " & e.Alt & vbCrLf & _ "Nilai Control " & e.Control & vbCrLf & _ "Nilai Handle " & e.Handled & vbCrLf & _ "Nilai KeyCode " & e.KeyCode & vbCrLf & _ "Nilai KeyValue " & e.KeyValue & vbCrLf & _ "Nilai Modifiers " & e.Modifiers & vbCrLf & _ "Nilai Shift " & e.Shift) End Sub End Class
Yang kalau kita tekan spasi akan menghasilkan msgbox berikut :
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 17
System.Windows.Forms.KeyPressEventHandle
Adapun tata cara penulisan event procedure untuk event yang menggunakan
KeyPressEventHandle adalah sebagai berikut :
Private Sub NamaKontrol_NamaEvent(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.NamaEvent
Informasi yang dapat diperoleh dari KeyEventArgs
Property Description
Handled Mendapatkan apakah event telah dihandle
KeyChar Mendapatkan karakter yang ditekan
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub Public Sub New() 'Constructor Me.Text = "Dengan pendekatan OOP" End Sub Private Sub MyForm_KeyPress(sender as Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress Msgbox("Nilai Handle " & e.Handled & vbCrLf & _ "Nilai KeyChar " & e.KeyChar & vbCrLf) End Sub
End Class
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 18
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 19
Menempatkan kontrol diatas form
Membuat Label
Berikut ini adalah koding untuk menempatkan sebuah label diatas form
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form Dim CatatEvent As String <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub Dim MyLabel As New System.Windows.Forms.Label 'Deklarasi Public Sub New() 'Constructor Me.Text = "Membuat kontrol pada Form" MyLabel.Text = "Ini adalah Label" MyLabel.Location = New System.Drawing.Point(100,100) 'Lokasi Me.Controls.Add(MyLabel) End Sub End Class
Membuat Textbox
Berikut ini adalah koding untuk menempatkan sebuah textbox diatas form
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 20
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form Dim CatatEvent As String <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub Dim MyText As New System.Windows.Forms.Textbox 'Deklarasi Public Sub New() 'Constructor Me.Text = "Membuat kontrol pada Form" MyText.Text = "Ini adalah Textbox" MyText.Location = New System.Drawing.Point(100,100) 'Lokasi MyText.Size = New System.Drawing.Size(140,250) 'Ukuran Me.Controls.Add(MyText) End Sub
End Class
Validasi pada textbox
Untuk melakukan validasi terhadap input yang dilakukan oleh pemakai pada textbox kita
dapat menggunakan event validating.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 21
Untuk menggunakan event pada kontrol, kita perlu mendeklarasikan variabel kontrol
beserta WithEvents.
Private Sub NamaTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles NamaTextbox.Validating Contoh :
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form Dim CatatEvent As String <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.EnableVisualStyles() System.Windows.Forms.Application.Run(New MyForm) End Sub Dim WithEvents MyText As New System.Windows.Forms.Textbox Public Sub New() 'Constructor Me.Text = "Membuat kontrol pada Form" MyText.Text = "Ini adalah Textbox" MyText.Location = New System.Drawing.Point(100,100) MyText.Size = New System.Drawing.Size(140,250) Me.Controls.Add(MyText) End Sub Private Sub MyText_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyText.Validating Msgbox("Panjang Text : " & MyText.Text.Length()) End Sub End Class
Membuat button
Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form Dim CatatEvent As String <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.Run(New MyForm) End Sub
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 22
Dim MyButton As New System.Windows.Forms.Button 'Deklarasi Public Sub New() 'Constructor Me.Text = "Membuat kontrol pada Form" MyButton.Text = "Ini adalah Button" MyButton.Location = New System.Drawing.Point(100,100) MyButton.Size = New System.Drawing.Size(120,25) Me.Controls.Add(MyButton) End Sub End Class
Event Click pada button
Pemakaian button umumnya adalah untuk proses klik oleh mouse, event procedure untuk
Click penulisannya adalah sebagai berikut :
Private Sub NamaButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NamaButton.Click Contoh : Option Explicit On Imports System Imports Microsoft.VisualBasic Public Class MyForm Inherits System.Windows.Forms.Form Dim CatatEvent As String <System.STAThread()> _ Public Shared Sub Main() System.Windows.Forms.Application.EnableVisualStyles()
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 23
System.Windows.Forms.Application.Run(New MyForm) End Sub Dim WithEvents MyButton As New System.Windows.Forms.Button Public Sub New() 'Constructor Me.Text = "Membuat kontrol pada Form" MyButton.Text = "Ini adalah Button" MyButton.Location = New System.Drawing.Point(100,100) Me.Controls.Add(MyButton) End Sub Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton.Click Msgbox("Terjadi event button click") End Sub End Class Yang kalau dijalankan, dan dilakukan klik pada button akan menampilkan pesan sebagai
berikut :
Latihan :
Buatlah program Windows Form untuk menghitung luas persegi panjang !
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 24
Membuat Aplikasi MDI Form
MDI Form
Untuk membuat MDI Form tidak jauh berbeda dengan pembuatan form biasanya, yang
perlu anda lakukan adalah dengan menset property IsMDIContainer menjadi True,
Contoh : Option Explicit On Imports System Imports System.Windows.Forms Imports Microsoft.VisualBasic Public Class MyMDI Inherits Form <System.STAThread()> _ Public Shared Sub Main() Application.Run(New MyMDI) End Sub Public Sub New() 'Constructor Me.Text = "Membuat MDI Form" Me.IsMDIContainer = True End Sub End Class
MDI Child
Pada dasarnya form MDI Child adalah sama dengan form biasanya, yang kemudian akan
ditamplkan oleh MDI Form.
Public Class MyForm Inherits Form Public Sub New() Me.Text = "MDI Child" End Sub End Class
Menampilkan MDI Child
Untuk menampilkan MDI Child pada MDI Form kita, adalah dengan :
1. Membuat instance dari Form yang akan dijadikan MDI Child
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 25
2. Kemudian kita set property MDIParent ke Form MDI
3. Menampilkan Form MDI Child dengan metoda Show()
Contoh :
Option Explicit On Imports System Imports System.Windows.Forms Imports Microsoft.VisualBasic Public Class MyMDI Inherits Form <System.STAThread()> _ Public Shared Sub Main() Application.Run(New MyMDI) End Sub Public Sub New() 'Constructor Me.Text = "Membuat MDI Form" Me.IsMDIContainer = True Dim MyChild As new MyForm 'Instance dari myform MyChild.MdiParent = Me 'set MDIParent MyChild.Show() 'tampilkan MDI Child End Sub End Class Public Class MyForm Inherits Form Public Sub New() Me.Text = "MDI Child" End Sub End Class
Pengaturan MDI Child pada MDI Form
Pengaturan susunan MDI Child pada MDI Form dapat dilakukan dengan menggunakan
metoda LayoutMDI(MDI layout).
Member name Description
ArrangeIcons All MDI child icons are arranged within the client region of the MDI parent form.
Cascade All MDI child windows are cascaded within the client region of the MDI parent form.
TileHorizontal All MDI child windows are tiled horizontally within the client region of the MDI parent form.
TileVertical All MDI child windows are tiled vertically within the client region of the MDI parent form.
Contoh :
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 26
Me.LayoutMDI(System.Windows.Forms.MDILayout.Cascade)
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 27
Membuat Menu
Untuk membuat menu pada form, anda dapat menggunakan langkah-langkah berikut ini :
1. Membuat instance dari komponen MainMenu, dan set sebagai menu untuk form
2. Membuat MenuItem untuk MainMenu, dan tambahkan pada collection object dari
MainMenu
3. Membuat SubMenuItem untuk MenuItem, dan tambahkan pada collection
masing-masing object MenuItem.
Contoh :
Option Explicit On Imports System Imports System.Windows.Forms Imports Microsoft.VisualBasic Public Class MyMDI Inherits Form <System.STAThread()> _ Public Shared Sub Main() Application.Run(New MyMDI) End Sub Public Sub New() 'Constructor Me.Text = "Membuat MDI Form" Me.IsMDIContainer = True AddMenu() End Sub Private Sub AddMenu() 'Membuat instance dari MainMenu dan set sebagai menu form Dim mnuUtama As new MainMenu() Me.Menu = mnuUtama 'membuat menuitem Dim mnuFile As new MenuItem("&File") Dim mnuWindow As new MenuItem("&Window") mnuUtama.MenuItems.Add(mnuFile) 'Tambahkan ke collection mnuUtama.MenuItems.Add(mnuWindow) 'membuat submenuitem untuk sub menu File Dim mnuFileNew As new MenuItem("&New") Dim mnuFileClose As new MenuItem("&Close") Dim mnuFileExit As new MenuItem("&Exit") mnuFile.MenuItems.Add(mnuFileNew) 'Tambahkan ke collection mnuFile.MenuItems.Add(mnuFileClose)
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 28
mnuFile.MenuItems.Add(mnuFileExit) End Sub End Class Public Class MyForm Inherits Form Public Sub New() Me.Text = "MDI Child" End Sub End Class Dan hasil eksekusinya adalah sebagai berikut :
Men-disable menuitem
Untuk mendisable menuitem, kita dapat menggunakan property Enabled pada menuitem
yang akan diatur keaktifannya.
Contoh :
mnuFileClose.Enabled = False atau
Me.Menu.MenuItems(0).MenuItems(2).Enabled = False
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 29
Menyembunyikan menuitem
Untuk menyembunyikan menuitem, kita dapat menggunakan property Visible pada
menuitem yang akan diatur kemunculannya.
Contoh :
mnuFileClose.Visible = False
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 30
Membuat garis pembatas pada menuitem
Untuk menbuat garis pembatas dan dapat membuat tanda – sebagai text untuk menu.
Contoh :
'membuat submenuitem untuk sub menu File Dim mnuFileNew As new MenuItem("&New") Dim mnuFileClose As new MenuItem("&Close") Dim mnuGaris11 As new MenuItem("-") Dim mnuFileExit As new MenuItem("&Exit") mnuFile.MenuItems.Add(mnuFileNew) 'Tambahkan ke collection mnuFile.MenuItems.Add(mnuFileClose) mnuFile.MenuItems.Add(mnuGaris11) mnuFile.MenuItems.Add(mnuFileExit)
Membuat tanda check pada menuitem
Untuk menbuat tanda check pada menuitem dapat dilakukan dengan property Checked.
Contoh :
mnuFileNew.Checked = True
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 31
Menambah shortcut key pada menuitem
Untuk menbuat tanda check pada menuitem dapat dilakukan dengan property Shortcut.
Contoh :
mnuFileNew.Shortcut = System.Windows.Forms.Shortcut.F2
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 32
Enumeration pada Shortcut
Member name Description
Alt0 The shortcut keys ALT+0.
Alt1 The shortcut keys ALT+1.
Alt2 The shortcut keys ALT+2.
Alt3 The shortcut keys ALT+3.
Alt4 The shortcut keys ALT+4.
Alt5 The shortcut keys ALT+5.
Alt6 The shortcut keys ALT+6.
Alt7 The shortcut keys ALT+7.
Alt8 The shortcut keys ALT+8.
Alt9 The shortcut keys ALT+9.
AltBksp The shortcut keys ALT+BACKSPACE.
AltF1 The shortcut keys ALT+F1.
AltF10 The shortcut keys ALT+F10.
AltF11 The shortcut keys ALT+F11.
AltF12 The shortcut keys ALT+F12.
AltF2 The shortcut keys ALT+F2.
AltF3 The shortcut keys ALT+F3.
AltF4 The shortcut keys ALT+F4.
AltF5 The shortcut keys ALT+F5.
AltF6 The shortcut keys ALT+F6.
AltF7 The shortcut keys ALT+F7.
AltF8 The shortcut keys ALT+F8.
AltF9 The shortcut keys ALT+F9.
Ctrl0 The shortcut keys CTRL+0.
Ctrl1 The shortcut keys CTRL+1.
Ctrl2 The shortcut keys CTRL+2.
Ctrl3 The shortcut keys CTRL+3.
Ctrl4 The shortcut keys CTRL+4.
Ctrl5 The shortcut keys CTRL+5.
Ctrl6 The shortcut keys CTRL+6.
Ctrl7 The shortcut keys CTRL+7.
Ctrl8 The shortcut keys CTRL+8.
Ctrl9 The shortcut keys CTRL+9.
CtrlA The shortcut keys CTRL+A.
CtrlB The shortcut keys CTRL+B.
CtrlC The shortcut keys CTRL+C.
CtrlD The shortcut keys CTRL+D.
CtrlDel The shortcut keys CTRL+DELETE.
CtrlE The shortcut keys CTRL+E.
CtrlF The shortcut keys CTRL+F.
CtrlF1 The shortcut keys CTRL+F1.
CtrlF10 The shortcut keys CTRL+F10.
CtrlF11 The shortcut keys CTRL+F11.
CtrlF12 The shortcut keys CTRL+F12.
CtrlF2 The shortcut keys CTRL+F2.
CtrlF3 The shortcut keys CTRL+F3.
CtrlF4 The shortcut keys CTRL+F4.
CtrlF5 The shortcut keys CTRL+F5.
CtrlF6 The shortcut keys CTRL+F6.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 33
CtrlF7 The shortcut keys CTRL+F7.
CtrlF8 The shortcut keys CTRL+F8.
CtrlF9 The shortcut keys CTRL+F9.
CtrlG The shortcut keys CTRL+G.
CtrlH The shortcut keys CTRL+H.
CtrlI The shortcut keys CTRL+I.
CtrlIns The shortcut keys CTRL+INSERT.
CtrlJ The shortcut keys CTRL+J.
CtrlK The shortcut keys CTRL+K.
CtrlL The shortcut keys CTRL+L.
CtrlM The shortcut keys CTRL+M.
CtrlN The shortcut keys CTRL+N.
CtrlO The shortcut keys CTRL+O.
CtrlP The shortcut keys CTRL+P.
CtrlQ The shortcut keys CTRL+Q.
CtrlR The shortcut keys CTRL+R.
CtrlS The shortcut keys CTRL+S.
CtrlShift0 The shortcut keys CTRL+SHIFT+0.
CtrlShift1 The shortcut keys CTRL+SHIFT+1.
CtrlShift2 The shortcut keys CTRL+SHIFT+2.
CtrlShift3 The shortcut keys CTRL+SHIFT+3.
CtrlShift4 The shortcut keys CTRL+SHIFT+4.
CtrlShift5 The shortcut keys CTRL+SHIFT+5.
CtrlShift6 The shortcut keys CTRL+SHIFT+6.
CtrlShift7 The shortcut keys CTRL+SHIFT+7.
CtrlShift8 The shortcut keys CTRL+SHIFT+8.
CtrlShift9 The shortcut keys CTRL+SHIFT+9.
CtrlShiftA The shortcut keys CTRL+SHIFT+A.
CtrlShiftB The shortcut keys CTRL+SHIFT+B.
CtrlShiftC The shortcut keys CTRL+SHIFT+C.
CtrlShiftD The shortcut keys CTRL+SHIFT+D.
CtrlShiftE The shortcut keys CTRL+SHIFT+E.
CtrlShiftF The shortcut keys CTRL+SHIFT+F.
CtrlShiftF1 The shortcut keys CTRL+SHIFT+F1.
CtrlShiftF10 The shortcut keys CTRL+SHIFT+F10.
CtrlShiftF11 The shortcut keys CTRL+SHIFT+F11.
CtrlShiftF12 The shortcut keys CTRL+SHIFT+F12.
CtrlShiftF2 The shortcut keys CTRL+SHIFT+F2.
CtrlShiftF3 The shortcut keys CTRL+SHIFT+F3.
CtrlShiftF4 The shortcut keys CTRL+SHIFT+F4.
CtrlShiftF5 The shortcut keys CTRL+SHIFT+F5.
CtrlShiftF6 The shortcut keys CTRL+SHIFT+F6.
CtrlShiftF7 The shortcut keys CTRL+SHIFT+F7.
CtrlShiftF8 The shortcut keys CTRL+SHIFT+F8.
CtrlShiftF9 The shortcut keys CTRL+SHIFT+F9.
CtrlShiftG The shortcut keys CTRL+SHIFT+G.
CtrlShiftH The shortcut keys CTRL+SHIFT+H.
CtrlShiftI The shortcut keys CTRL+SHIFT+I.
CtrlShiftJ The shortcut keys CTRL+SHIFT+J.
CtrlShiftK The shortcut keys CTRL+SHIFT+K.
CtrlShiftL The shortcut keys CTRL+SHIFT+L.
CtrlShiftM The shortcut keys CTRL+SHIFT+M.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 34
CtrlShiftN The shortcut keys CTRL+SHIFT+N.
CtrlShiftO The shortcut keys CTRL+SHIFT+O.
CtrlShiftP The shortcut keys CTRL+SHIFT+P.
CtrlShiftQ The shortcut keys CTRL+SHIFT+Q.
CtrlShiftR The shortcut keys CTRL+SHIFT+R.
CtrlShiftS The shortcut keys CTRL+SHIFT+S.
CtrlShiftT The shortcut keys CTRL+SHIFT+T.
CtrlShiftU The shortcut keys CTRL+SHIFT+U.
CtrlShiftV The shortcut keys CTRL+SHIFT+V.
CtrlShiftW The shortcut keys CTRL+SHIFT+W.
CtrlShiftX The shortcut keys CTRL+SHIFT+X.
CtrlShiftY The shortcut keys CTRL+SHIFT+Y.
CtrlShiftZ The shortcut keys CTRL+SHIFT+Z.
CtrlT The shortcut keys CTRL+T.
CtrlU The shortcut keys CTRL+U
CtrlV The shortcut keys CTRL+V.
CtrlW The shortcut keys CTRL+W.
CtrlX The shortcut keys CTRL+X.
CtrlY The shortcut keys CTRL+Y.
CtrlZ The shortcut keys CTRL+Z.
Del The shortcut key DELETE.
F1 The shortcut key F1.
F10 The shortcut key F10.
F11 The shortcut key F11.
F12 The shortcut key F12.
F2 The shortcut key F2.
F3 The shortcut key F3.
F4 The shortcut key F4.
F5 The shortcut key F5.
F6 The shortcut key F6.
F7 The shortcut key F7.
F8 The shortcut key F8.
F9 The shortcut key F9.
Ins The shortcut key INSERT.
None No shortcut key is associated with the menu item.
ShiftDel The shortcut keys SHIFT+DELETE.
ShiftF1 The shortcut keys SHIFT+F1.
ShiftF10 The shortcut keys SHIFT+F10.
ShiftF11 The shortcut keys SHIFT+F11.
ShiftF12 The shortcut keys SHIFT+F12.
ShiftF2 The shortcut keys SHIFT+F2.
ShiftF3 The shortcut keys SHIFT+F3.
ShiftF4 The shortcut keys SHIFT+F4.
ShiftF5 The shortcut keys SHIFT+F5.
ShiftF6 The shortcut keys SHIFT+F6.
ShiftF7 The shortcut keys SHIFT+F7.
ShiftF8 The shortcut keys SHIFT+F8.
ShiftF9 The shortcut keys SHIFT+F9.
ShiftIns The shortcut keys SHIFT+INSERT.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 35
Lampiran
Kontrol pada System.Windows.Forms
Berikut ini adalah daftar control yang dapat ditempatkan diatas form menurut fungsinya :
Function Control Description
Text edit TextBox Displays text entered at design time that can be edited by users at run time, or changed programmatically.
RichTextBox Enables text to be displayed with formatting in plain text or rich-text format (RTF).
Text display (read-only) Label Displays text that users cannot directly edit.
LinkLabel Displays text as a Web-style link and triggers an event when the user clicks the special text. Usually the text is a link to another window or a Web site.
StatusBar Displays information about the application's current state using a framed window, usually at the bottom of a parent form.
Selection from a list CheckedListBox Displays a scrollable list of items, each accompanied by a check box.
ComboBox Displays a drop-down list of items.
DomainUpDown Displays a list of text items that users can scroll through with up and down buttons.
ListBox Displays a list of text and graphical items (icons).
ListView Displays items in one of four different views. Views include text only, text with small icons, text with large icons, and a details view.
NumericUpDown Displays a list of numerals that users can scroll through with up and down buttons.
TreeView Displays a hierarchical collection of node objects that can consist of text with optional check boxes or icons.
Graphics display PictureBox Displays graphical files, such as bitmaps and icons, in a frame.
Graphics storage ImageList Serves as a repository for images. ImageList controls and the images they contain can be
reused from one application to the next.
Value setting CheckBox Displays a check box and a label for text. Generally used to set options.
CheckedListBox Displays a scrollable list of items, each accompanied by a check box.
RadioButton Displays a button that can be turned on or off.
Trackbar Allows users to set values on a scale by moving a "thumb" along a scale.
Date setting DateTimePicker Displays a graphical calendar to allow users to select a date or a time.
MonthCalendar Displays a graphical calendar to allow users to select a range of dates.
Dialog boxes ColorDialog Displays the color picker dialog box that allows users to set the color of an interface element.
FontDialog Displays a dialog box that allows users to set a
font and its attributes.
OpenFileDialog Displays a dialog box that allows users to navigate to and select a file.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 36
PrintDialog Displays a dialog box that allows users to select a printer and set its attributes.
PrintPreviewDialog Displays a dialog box that displays how a PrintDocument object will appear when printed.
SaveFileDialog Displays a dialog box that allows users to save a file.
Menu controls MainMenu Provides a design-time interface for creating menus.
ContextMenu Implements a menu that appears when the user right-clicks an object.
Commands Button Used to start, stop, or interrupt a process.
LinkLabel Displays text as a Web-style link and triggers an event when the user clicks the special text. Usually the text is a link to another window or a Web site.
NotifyIcon Displays an icon in the status notification area of the taskbar that represents an application running in the background.
ToolBar Contains a collection of button controls.
Grouping other controls Panel Groups a set of controls on an unlabeled, scrollable frame.
GroupBox Groups a set of controls (such as radio buttons) on a labeled, nonscrollable frame.
TabControl Provides a tabbed page for organizing and accessing grouped objects efficiently.
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 37
Keys Enumeration
Members
Member name Description Value
A
Supported by the .NET Compact
Framework.
The A key. 65
Add
Supported by the .NET Compact
Framework.
The add key. 107
Alt
Supported by the .NET Compact
Framework.
The ALT modifier key. 262144
Apps
Supported by the .NET Compact Framework.
The application key (Microsoft Natural Keyboard). 93
Attn
Supported by the .NET Compact
Framework.
The ATTN key. 246
B
Supported by the .NET Compact Framework.
The B key. 66
Back
Supported by the .NET Compact
Framework.
The BACKSPACE key. 8
BrowserBack The browser back key (Windows 2000 or later). 166
BrowserFavorites The browser favorites key (Windows 2000 or later). 171
BrowserForward The browser forward key (Windows 2000 or later). 167
BrowserHome The browser home key (Windows 2000 or later). 172
BrowserRefresh The browser refresh key (Windows 2000 or later). 168
BrowserSearch The browser search key (Windows 2000 or later). 170
BrowserStop The browser stop key (Windows 2000 or later). 169
C
Supported by the .NET Compact Framework.
The C key. 67
Cancel
Supported by the .NET Compact
Framework.
The CANCEL key. 3
Capital
Supported by the .NET Compact
Framework.
The CAPS LOCK key. 20
CapsLock The CAPS LOCK key. 20
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 38
Supported by the .NET Compact
Framework.
Clear
Supported by the .NET Compact Framework.
The CLEAR key. 12
Control
Supported by the .NET Compact
Framework.
The CTRL modifier key. 131072
ControlKey
Supported by the .NET Compact
Framework.
The CTRL key. 17
Crsel
Supported by the .NET Compact
Framework.
The CRSEL key. 247
D
Supported by the .NET Compact
Framework.
The D key. 68
D0
Supported by the .NET Compact Framework.
The 0 key. 48
D1
Supported by the .NET Compact
Framework.
The 1 key. 49
D2
Supported by the .NET Compact Framework.
The 2 key. 50
D3
Supported by the .NET Compact
Framework.
The 3 key. 51
D4
Supported by the .NET Compact
Framework.
The 4 key. 52
D5
Supported by the .NET Compact
Framework.
The 5 key. 53
D6
Supported by the .NET Compact
Framework.
The 6 key. 54
D7
Supported by the .NET Compact Framework.
The 7 key. 55
D8 The 8 key. 56
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 39
Supported by the .NET Compact
Framework.
D9
Supported by the .NET Compact Framework.
The 9 key. 57
Decimal
Supported by the .NET Compact
Framework.
The decimal key. 110
Delete
Supported by the .NET Compact
Framework.
The DEL key. 46
Divide
Supported by the .NET Compact
Framework.
The divide key. 111
Down
Supported by the .NET Compact
Framework.
The DOWN ARROW key. 40
E
Supported by the .NET Compact Framework.
The E key. 69
End
Supported by the .NET Compact
Framework.
The END key. 35
Enter
Supported by the .NET Compact Framework.
The ENTER key. 13
EraseEof
Supported by the .NET Compact
Framework.
The ERASE EOF key. 249
Escape
Supported by the .NET Compact
Framework.
The ESC key. 27
Execute
Supported by the .NET Compact
Framework.
The EXECUTE key. 43
Exsel
Supported by the .NET Compact
Framework.
The EXSEL key. 248
F
Supported by the .NET Compact Framework.
The F key. 70
F1 The F1 key. 112
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 40
Supported by the .NET Compact
Framework.
F10
Supported by the .NET Compact Framework.
The F10 key. 121
F11
Supported by the .NET Compact
Framework.
The F11 key. 122
F12
Supported by the .NET Compact
Framework.
The F12 key. 123
F13
Supported by the .NET Compact
Framework.
The F13 key. 124
F14
Supported by the .NET Compact
Framework.
The F14 key. 125
F15
Supported by the .NET Compact Framework.
The F15 key. 126
F16
Supported by the .NET Compact
Framework.
The F16 key. 127
F17
Supported by the .NET Compact Framework.
The F17 key. 128
F18
Supported by the .NET Compact
Framework.
The F18 key. 129
F19
Supported by the .NET Compact
Framework.
The F19 key. 130
F2
Supported by the .NET Compact
Framework.
The F2 key. 113
F20
Supported by the .NET Compact
Framework.
The F20 key. 131
F21
Supported by the .NET Compact Framework.
The F21 key. 132
F22 The F22 key. 133
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 41
Supported by the .NET Compact
Framework.
F23
Supported by the .NET Compact Framework.
The F23 key. 134
F24
Supported by the .NET Compact
Framework.
The F24 key. 135
F3
Supported by the .NET Compact
Framework.
The F3 key. 114
F4
Supported by the .NET Compact
Framework.
The F4 key. 115
F5
Supported by the .NET Compact
Framework.
The F5 key. 116
F6
Supported by the .NET Compact Framework.
The F6 key. 117
F7
Supported by the .NET Compact
Framework.
The F7 key. 118
F8
Supported by the .NET Compact Framework.
The F8 key. 119
F9
Supported by the .NET Compact
Framework.
The F9 key. 120
FinalMode The IME final mode key. 24
G
Supported by the .NET Compact Framework.
The G key. 71
H
Supported by the .NET Compact
Framework.
The H key. 72
HanguelMode The IME Hanguel mode key. (maintained for compatibility; use HangulMode)
21
HangulMode The IME Hangul mode key. 21
HanjaMode The IME Hanja mode key. 25
Help
Supported by the .NET Compact
Framework.
The HELP key. 47
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 42
Home
Supported by the .NET Compact
Framework.
The HOME key. 36
I
Supported by the .NET Compact Framework.
The I key. 73
IMEAceept The IME accept key. 30
IMEConvert The IME convert key. 28
IMEModeChange The IME mode change key. 31
IMENonconvert The IME nonconvert key. 29
Insert
Supported by the .NET Compact Framework.
The INS key. 45
J
Supported by the .NET Compact
Framework.
The J key. 74
JunjaMode The IME Junja mode key. 23
K
Supported by the .NET Compact Framework.
The K key. 75
KanaMode The IME Kana mode key. 21
KanjiMode The IME Kanji mode key. 25
KeyCode
Supported by the .NET Compact
Framework.
The bitmask to extract a key code from a key value. 65535
L
Supported by the .NET Compact Framework.
The L key. 76
LaunchApplication1 The start application one key (Windows 2000 or later). 182
LaunchApplication2 The start application two key (Windows 2000 or later). 183
LaunchMail The launch mail key (Windows 2000 or later). 180
LButton
Supported by the .NET Compact Framework.
The left mouse button. 1
LControlKey
Supported by the .NET Compact
Framework.
The left CTRL key. 162
Left
Supported by the .NET Compact
Framework.
The LEFT ARROW key. 37
LineFeed
Supported by the .NET Compact
Framework.
The LINEFEED key. 10
LMenu The left ALT key. 164
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 43
Supported by the .NET Compact
Framework.
LShiftKey
Supported by the .NET Compact Framework.
The left SHIFT key. 160
LWin
Supported by the .NET Compact
Framework.
The left Windows logo key (Microsoft Natural Keyboard).
91
M
Supported by the .NET Compact
Framework.
The M key. 77
MButton
Supported by the .NET Compact
Framework.
The middle mouse button (three-button mouse). 4
MediaNextTrack The media next track key (Windows 2000 or later). 176
MediaPlayPause The media play pause key (Windows 2000 or later). 179
MediaPreviousTrack The media previous track key (Windows 2000 or later).
177
MediaStop The media Stop key (Windows 2000 or later). 178
Menu
Supported by the .NET Compact
Framework.
The ALT key. 18
Modifiers
Supported by the .NET Compact
Framework.
The bitmask to extract modifiers from a key value. -65536
Multiply
Supported by the .NET Compact Framework.
The multiply key. 106
N
Supported by the .NET Compact
Framework.
The N key. 78
Next
Supported by the .NET Compact Framework.
The PAGE DOWN key. 34
NoName
Supported by the .NET Compact
Framework.
A constant reserved for future use. 252
None
Supported by the .NET Compact
Framework.
No key pressed. 0
NumLock
Supported by the .NET Compact
Framework.
The NUM LOCK key. 144
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 44
NumPad0
Supported by the .NET Compact
Framework.
The 0 key on the numeric keypad. 96
NumPad1
Supported by the .NET Compact Framework.
The 1 key on the numeric keypad. 97
NumPad2
Supported by the .NET Compact
Framework.
The 2 key on the numeric keypad. 98
NumPad3
Supported by the .NET Compact
Framework.
The 3 key on the numeric keypad. 99
NumPad4
Supported by the .NET Compact
Framework.
The 4 key on the numeric keypad. 100
NumPad5
Supported by the .NET Compact
Framework.
The 5 key on the numeric keypad. 101
NumPad6
Supported by the .NET Compact Framework.
The 6 key on the numeric keypad. 102
NumPad7
Supported by the .NET Compact
Framework.
The 7 key on the numeric keypad. 103
NumPad8
Supported by the .NET Compact Framework.
The 8 key on the numeric keypad. 104
NumPad9
Supported by the .NET Compact
Framework.
The 9 key on the numeric keypad. 105
O
Supported by the .NET Compact
Framework.
The O key. 79
Oem8 OEM specific. 223
OemBackslash The OEM angle bracket or backslash key on the RT 102 key keyboard (Windows 2000 or later).
226
OemClear
Supported by the .NET Compact
Framework.
The CLEAR key. 254
OemCloseBrackets The OEM close bracket key on a US standard keyboard (Windows 2000 or later).
221
Oemcomma The OEM comma key on any country/region keyboard (Windows 2000 or later).
188
OemMinus The OEM minus key on any country/region keyboard 189
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 45
(Windows 2000 or later).
OemOpenBrackets The OEM open bracket key on a US standard keyboard (Windows 2000 or later).
219
OemPeriod The OEM period key on any country/region keyboard (Windows 2000 or later).
190
OemPipe The OEM pipe key on a US standard keyboard (Windows 2000 or later).
220
Oemplus The OEM plus key on any country/region keyboard (Windows 2000 or later).
187
OemQuestion The OEM question mark key on a US standard keyboard (Windows 2000 or later).
191
OemQuotes The OEM singled/double quote key on a US standard keyboard (Windows 2000 or later).
222
OemSemicolon The OEM semicolon key on a US standard keyboard (Windows 2000 or later).
186
Oemtilde The OEM tilde key on a US standard keyboard (Windows 2000 or later).
192
P
Supported by the .NET Compact
Framework.
The P key. 80
Pa1
Supported by the .NET Compact Framework.
The PA1 key. 253
PageDown
Supported by the .NET Compact
Framework.
The PAGE DOWN key. 34
PageUp
Supported by the .NET Compact Framework.
The PAGE UP key. 33
Pause
Supported by the .NET Compact
Framework.
The PAUSE key. 19
Play
Supported by the .NET Compact
Framework.
The PLAY key. 250
Supported by the .NET Compact
Framework.
The PRINT key. 42
PrintScreen
Supported by the .NET Compact
Framework.
The PRINT SCREEN key. 44
Prior
Supported by the .NET Compact Framework.
The PAGE UP key. 33
ProcessKey
Supported by the .NET Compact
Framework.
The PROCESS KEY key. 229
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 46
Q
Supported by the .NET Compact
Framework.
The Q key. 81
R
Supported by the .NET Compact Framework.
The R key. 82
RButton
Supported by the .NET Compact
Framework.
The right mouse button. 2
RControlKey
Supported by the .NET Compact
Framework.
The right CTRL key. 163
Return
Supported by the .NET Compact
Framework.
The RETURN key. 13
Right
Supported by the .NET Compact
Framework.
The RIGHT ARROW key. 39
RMenu
Supported by the .NET Compact Framework.
The right ALT key. 165
RShiftKey
Supported by the .NET Compact
Framework.
The right SHIFT key. 161
RWin
Supported by the .NET Compact Framework.
The right Windows logo key (Microsoft Natural Keyboard).
92
S
Supported by the .NET Compact
Framework.
The S key. 83
Scroll
Supported by the .NET Compact
Framework.
The SCROLL LOCK key. 145
Select
Supported by the .NET Compact
Framework.
The SELECT key. 41
SelectMedia The select media key (Windows 2000 or later). 181
Separator
Supported by the .NET Compact
Framework.
The separator key. 108
Shift
Supported by the .NET Compact
The SHIFT modifier key. 65536
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 47
Framework.
ShiftKey
Supported by the .NET Compact
Framework.
The SHIFT key. 16
Snapshot
Supported by the .NET Compact Framework.
The PRINT SCREEN key. 44
Space
Supported by the .NET Compact
Framework.
The SPACEBAR key. 32
Subtract
Supported by the .NET Compact Framework.
The subtract key. 109
T
Supported by the .NET Compact
Framework.
The T key. 84
Tab
Supported by the .NET Compact
Framework.
The TAB key. 9
U
Supported by the .NET Compact
Framework.
The U key. 85
Up
Supported by the .NET Compact
Framework.
The UP ARROW key. 38
V
Supported by the .NET Compact Framework.
The V key. 86
VolumeDown The volume down key (Windows 2000 or later). 174
VolumeMute The volume mute key (Windows 2000 or later). 173
VolumeUp The volume up key (Windows 2000 or later). 175
W
Supported by the .NET Compact Framework.
The W key. 87
X
Supported by the .NET Compact
Framework.
The X key. 88
XButton1
Supported by the .NET Compact
Framework.
The first x mouse button (five-button mouse). 5
XButton2
Supported by the .NET Compact
Framework.
The second x mouse button (five-button mouse). 6
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 48
Y
Supported by the .NET Compact
Framework.
The Y key. 89
Z
Supported by the .NET Compact Framework.
The Z key. 90
Zoom
Supported by the .NET Compact
Framework.
The ZOOM key. 251
Pemrograman Form pada VB.NET Hendra, S.T.
INDOPROG 49
Daftar Pustaka
.NET Framework SDK documentation, Microsoft Corporation