Senin, 30 Desember 2013

“Type of Numbers” dengan Visual Basic.NET 2010

Type of Numbers vb.net

Seperti biasa setelah sebelumnya saya terapkan aplikasi serupa dengan Visual Basic 6 sekarang saya terapkan pada Visual Basic.NET 2010. Baik dalam design tampilan dan logika coding program tidak ada yang berubah hanya saja dalam penamaan kontrol dan teknik seting yang agak berbeda. Tapi saya mengalami kendala untuk path kerja, karena belum menemukan solusi yang terbaik. Dan bilamana ada diantara teman-teman yang dapat memberi masukan dengan masalah ini, tolong beritahukan saya dan Trims.

1. Jalankan terlebih dahulu aplikasi Visual Basic 2010

2. Pada tabulasi “Start Page” pilih “New Project” atau bisa juga dengan menekan tombol “Ctrl + N” pada keyboard

3. Pada jendela “New Project” pilih “Windows Forms Application” kemudian tekan tombol “OK

4. Berikut setingan kontrol properti yang terdapat pada aplikasi ini

Object Name Properties Setting
Form Form1 Font Tahoma; 10pt
    Form Border Style Fixed Single
    Maximize Box False
    Minimize Box False
    Start Position Center Screen
    Text Type of Numbers
Label Label1 Text Number:
Text Box TextBox1 Font Tahoma; 14pt
    Text Align Right
Button Button1 Text Analyze
Picture Box PictureBox1 Size Mode Stretch Image
Label Label2 Text Natural numbers
Picture Box PictureBox2 Size Mode Stretch Image
Label Label3 Text Integer
Picture Box PictureBox3 Size Mode Stretch Image
Label Label4 Text Even number
Picture Box PictureBox4 Size Mode Stretch Image
Label Label5 Text Odd number
Button Button2 Text Clear

5. Berikut event code program

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = TextBox1.Text Then PictureBox2.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\1.jpg")

        If CDbl(TextBox1.Text) >= 0 Then
            PictureBox1.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\1.jpg")
        Else
            PictureBox1.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\0.jpg")
        End If

        If Val(TextBox1.Text) Mod 2 = 0 Then
            PictureBox3.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\1.jpg")
        Else
            PictureBox3.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\0.jpg")
        End If

        If Val(TextBox1.Text) Mod 2 Then
            PictureBox4.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\1.jpg")
        Else
            PictureBox4.Image = Image.FromFile("D:\My Documents\VB.NET\Type Numbers\Type Numbers\Images\0.jpg")
        End If
        Button2.Focus()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        PictureBox1.Image = Nothing
        PictureBox2.Image = Nothing
        PictureBox3.Image = Nothing
        PictureBox4.Image = Nothing
        TextBox1.Focus()
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not (e.KeyChar >= ChrW(Keys.D0) And e.KeyChar <= ChrW(Keys.D9) Or e.KeyChar = ChrW(45) Or e.KeyChar = ChrW(Keys.Back) Or e.KeyChar = ChrW(Keys.Return)) Then
            e.KeyChar = ChrW(0)
        ElseIf e.KeyChar = ChrW(Keys.Return) Then
            Button1_Click(Nothing, Nothing)
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Button1.Enabled = True
        Button2.Enabled = True

        If TextBox1.Text = "" Then
            Button1.Enabled = False
            Button2.Enabled = False
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MsgBox("Exit the Aplication?", vbYesNo + vbQuestion, "Confirmation") = vbNo Then
            If e.CloseReason = CloseReason.UserClosing Then
                e.Cancel = True
            End If
        End If
    End Sub
End Class

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda