MsgBox (Kotak Pesan)

Berfungsi untuk menampilkan pesan atau komentar dalam bentuk form.

Bentuk Perintah

MsgBox(“Isi Pesan“, MsgBoxStyle, “Judul Pesan“)


Keterangan gambar:
  1. Judul Pesan
  2. Msgboxstyle
  3. Isi Pesan

Ada beberapa MsgBoxStyle, yaitu:
  1. MsgBoxStyle.Critical(16)               : Tombol Ok dan gambar icon Critical 
  2. MsgBoxStyle.Question(32)             : Tombol Ok dan gambar icon Question
  3. MsgBoxStyle.Exclamation(48)       : Tombol Ok dan gambar icon Exclamation
  4. MsgBoxStyle.Information(64)        : Tombol Ok dan gambar icon Information
  5. MsgBoxStyle.AbortRetryIgnore(2) : Tombol Abourt,Retry dan Ignore
  6. MsgBoxStyle.OkCancel(1)              : Tombol OK dan Cancel
  7. MsgBoxStyle.Ok Only(0)                : Tombol OK
  8. MsgBoxStyle.RetryCancel(5)          : Tombol Retry dan Cancel
  9. MsgBoxStyle.YesNo(4)                   : Tombol Yes dan No
  10. MsgBoxStyle.YesNoCancel(3)        : Tombol Yes,No dan Cancel
Contoh 1:
Membuat Form Login dengan tampilan sbb:

 

 
Alur Program:
-   Input Password.
-   Klik Proses
-   Jika Password benar maka akan tampil kotak pesan (MessageBox) dengan tampilan sbb:
·   Isi pesan        :  Password yang Anda Masukkan Benar
·   Judul Pesan   :  Info Login
·   MsgBoxStyle :  Tombol OK dengan gambar icon Information.
-   Jika Password salah maka akan tampil kotak pesan (MessageBox) dengan tampilan sbb:
·   Isi pesan        :  Password yang Anda Masukkan Salah”
·   Judul Pesan   : Info Login
·   MsgBoxStyle :  Tombol OK dengan gambar icon Critical.


Kode Program:
Kode program diketik pada Objek BtnProses (Tombol Proses)  sbb:
Private Sub BtnProses_Click(ByVal sender As System.Object, ...
    If TxtPas.Text = "rahasia" Then
        MsgBox("Password yang Anda Masukkan Benar",
                MsgBoxStyle.Information, "Info Login")
    Else
        MsgBox("Password yang Anda Masukkan Salah", 16, "Info")
    End If  
End Sub
Private Sub txtpas_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtpas.KeyPress


If e.KeyChar = Chr(13) Then
'btnproses.Focus()
btnproses_Click(sender,NewSystem.EventArgs())
End If
End Sub

Contoh 2:
Tambah tombol Tutup pada form Login, sehingga tampilan form menjadi seperti berikut:
Buat Perintah untuk Tombol Tutup menggunakan MessageBox dengan tampilan sbb:
-   Isi Pesan        :   “Apakah Anda ingin menutup Form Login ini?“
-   MsgBoxStyle  :   Yes dan No dengan icon Question.
-   Judul              :   “Tutup Form Login“

Alur Program:
Jika diklik tombol Yes, maka Program akan ditutup. Jika diklik tombol No, maka Program tidak akan ditutup.

Perintah Program:
Private Sub BtnTutup_Click(ByVal sender As System.Object, ...
    Dim pesan As String
    pesan = MsgBox("Apakah Anda ingin menutup Program ini?", MsgBoxStyle.YesNo + 32, "Tutup Program")
    If pesan = vbYes Then
        End
    Else
        Exit Sub
    End If
End Sub
 


Kenggunaan Messege Box

Posted by : Unknown 0 Comments

- Copyright © Visual Basic - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -