2nd Modifikasi aplikasi “Hello, World” dengan Visual Basic.NET 2010
Setelah sebelumnya saya sudah memposting pembuatan aplikasi serupa pada Visual Basic 6 sekarang saya terapkan pada Visual Basic.NET 2010. Seperti yang dapat teman-teman lihat tidak ada perbedaan dalam kontrol yang dipakai. Oleh karena itu teman-teman dapat membandingkan perbedaan di antara kedua buah bahasa pemrograman ini. Mana yang lebih baik diantara ke duanya? teman-temandapat memutuskannya sendiri
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 | Form Border Style | Fixed Single |
Maximize Box | False | ||
Minimize Box | False | ||
Start Position | Center Screen | ||
Text | Hello World | ||
Label | lblName | Font | Arial; 10pt |
Text | Type Your Name: | ||
Text Box | txtName | Font | Arial; 12pt |
Label | lblShow | Back Color | White |
Font | Arial; 24pt | ||
Text Align | Middle Center | ||
Button | cmdClickHere | Font | Arial; 10pt |
Text | Click Here | ||
Group Box | fraBackForm | Font | Arial; 10pt |
Text | Background (RGB) | ||
High Scrolls Bar | hsbRed | Large Change | 30 |
Maximum | 255 | ||
High Scrolls Bar | hsbGreen | Large Change | 30 |
Maximum | 255 | ||
High Scrolls Bar | hsbBlue | Large Change | 30 |
Maximum | 255 | ||
Button | cmdExit | Font | Arial; 10pt |
Text | E&xit | ||
Group Box | fraShowFont | Font | Arial; 10pt |
Text | Font Properties | ||
Label | lblFontAlignment | Font | Arial; 10pt |
Text | Alignment: | ||
Combo Box | cmbAlignment | Drop Down Style | Drop Down List |
Enabled | False | ||
Font | Arial; 10pt | ||
Items | Left Justify | ||
Group Box | fraFontColor | Font | Arial; 10pt |
Text | Color | ||
Radio Button | optRed | Enabled | False |
Font | Arial; 10pt | ||
Text | Red | ||
Radio Button | optGreen | Enabled | False |
Font | Arial; 10pt | ||
Text | Green | ||
Radio Button | optBlue | Enabled | False |
Font | Arial; 10pt | ||
Text | Blue | ||
Radio Button | optYellow | Enabled | False |
Font | Arial; 10pt | ||
Text | Yellow | ||
Group Box | fraFontStyle | Font | Arial; 10pt |
Text | Style | ||
Check Box | chkBold | Enabled | False |
Font | Arial; 10pt | ||
Text | Bold | ||
Check Box | chkItalic | Enabled | False |
Font | Arial; 10pt | ||
Text | Italic | ||
Check Box | chkUnderline | Enabled | False |
Font | Arial; 10pt | ||
Text | Underline | ||
Check Box | chkStrikethru | Enabled | False |
Font | Arial; 10pt | ||
Text | Strikethrough |
5. Berikut event code program
Public Class Form1
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Dim Response = MsgBox("Close the program", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirmation")
If Response = MsgBoxResult.Yes Then
End
End If
End Sub
Private Sub txtName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then
cmdClickHere_Click(sender, New EventArgs())
End If
End Sub
Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
cmdClickHere.Enabled = True
If txtName.Text = "" Then
cmdClickHere.Enabled = False
End If
End Sub
Private Sub cmdClickHere_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClickHere.Click
If cmdClickHere.Text = "Click Here" Then
lblShow.Text = txtName.Text
txtName.Enabled = False
cmbAlignment.Enabled = True
optRed.Enabled = True
optGreen.Enabled = True
optBlue.Enabled = True
optYellow.Enabled = True
chkBold.Enabled = True
chkItalic.Enabled = True
chkUnderline.Enabled = True
chkStrikethru.Enabled = True
cmdClickHere.Text = "New"
ElseIf cmdClickHere.Text = "New" Then
txtName.Enabled = True
txtName.Text = ""
txtName.Focus()
lblShow.Text = ""
lblShow.TextAlign = ContentAlignment.MiddleCenter
cmbAlignment.Items.Clear()
cmbAlignment.Items.Add("Left Justify")
cmbAlignment.Items.Add("Center")
cmbAlignment.Items.Add("Right Justify")
cmbAlignment.Enabled = False
optRed.Enabled = False
optGreen.Enabled = False
optBlue.Enabled = False
optYellow.Enabled = False
chkBold.Enabled = False
chkItalic.Enabled = False
chkUnderline.Enabled = False
chkStrikethru.Enabled = False
optRed.Checked = False
optGreen.Checked = False
optBlue.Checked = False
optYellow.Checked = False
chkBold.Checked = False
chkItalic.Checked = False
chkUnderline.Checked = False
chkStrikethru.Checked = False
cmdClickHere.Text = "Click Here"
End If
End Sub
Private Sub hsbRed_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbRed.Scroll
Me.BackColor = Color.FromArgb(hsbRed.Value, hsbGreen.Value, hsbBlue.Value)
End Sub
Private Sub optRed_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optRed.CheckedChanged
lblShow.ForeColor = Color.Red
End Sub
Private Sub optGreen_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optGreen.CheckedChanged
lblShow.ForeColor = Color.Green
End Sub
Private Sub optBlue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optBlue.CheckedChanged
lblShow.ForeColor = Color.Blue
End Sub
Private Sub optYellow_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optYellow.CheckedChanged
lblShow.ForeColor = Color.Yellow
End Sub
Private Sub cmbAlignment_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbAlignment.SelectedIndexChanged
Select Case cmbAlignment.SelectedIndex
Case 0
lblShow.TextAlign = ContentAlignment.MiddleLeft
Case 1
lblShow.TextAlign = ContentAlignment.MiddleCenter
Case 2
lblShow.TextAlign = ContentAlignment.MiddleRight
End Select
End Sub
Private Sub chkBold_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged
If chkBold.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold)
Else
lblShow.Font = New Font("Arial", 24, FontStyle.Regular)
End If
FontStyleChecked()
End Sub
Private Sub chkItalic_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkItalic.CheckedChanged
If chkItalic.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Italic)
Else
lblShow.Font = New Font("Arial", 24, FontStyle.Regular)
End If
FontStyleChecked()
End Sub
Private Sub chkUnderline_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUnderline.CheckedChanged
If chkUnderline.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Underline)
Else
lblShow.Font = New Font("Arial", 24, FontStyle.Regular)
End If
FontStyleChecked()
End Sub
Private Sub chkStrikethru_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStrikethru.CheckedChanged
If chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Strikeout)
Else
lblShow.Font = New Font("Arial", 24, FontStyle.Regular)
End If
FontStyleChecked()
End Sub
Private Sub FontStyleChecked()
If chkBold.Checked = True And chkItalic.Checked = True And chkUnderline.Checked = True And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline Or FontStyle.Strikeout)
ElseIf chkBold.Checked = False And chkItalic.Checked = True And chkUnderline.Checked = True And chkStrikethru.Enabled = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Italic Or FontStyle.Underline Or FontStyle.Strikeout)
ElseIf chkBold.Checked = True And chkItalic.Checked = False And chkUnderline.Checked = True And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Underline Or FontStyle.Strikeout)
ElseIf chkBold.Checked = True And chkItalic.Checked = True And chkUnderline.Checked = False And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic Or FontStyle.Strikeout)
ElseIf chkBold.Checked = True And chkItalic.Checked = True And chkUnderline.Checked = True And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline)
ElseIf chkBold.Checked = False And chkItalic.Checked = False And chkUnderline.Checked = True And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Underline Or FontStyle.Strikeout)
ElseIf chkBold.Checked = True And chkItalic.Checked = True And chkUnderline.Checked = False And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic)
ElseIf chkBold.Checked = True And chkItalic.Checked = False And chkUnderline.Checked = True And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Underline)
ElseIf chkBold.Checked = False And chkItalic.Checked = True And chkUnderline.Checked = False And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Italic Or FontStyle.Strikeout)
ElseIf chkBold.Checked = False And chkItalic.Checked = True And chkUnderline.Checked = True And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Italic Or FontStyle.Underline)
ElseIf chkBold.Checked = True And chkItalic.Checked = False And chkUnderline.Checked = False And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold Or FontStyle.Strikeout)
ElseIf chkBold.Checked = True And chkItalic.Checked = False And chkUnderline.Checked = False And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Bold)
ElseIf chkBold.Checked = False And chkItalic.Checked = True And chkUnderline.Checked = False And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Italic)
ElseIf chkBold.Checked = False And chkItalic.Checked = False And chkUnderline.Checked = True And chkStrikethru.Checked = False Then
lblShow.Font = New Font("Arial", 24, FontStyle.Underline)
ElseIf chkBold.Checked = False And chkItalic.Checked = False And chkUnderline.Checked = False And chkStrikethru.Checked = True Then
lblShow.Font = New Font("Arial", 24, FontStyle.Strikeout)
End If
End Sub
Private Sub hsbGreen_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbGreen.Scroll
Me.BackColor = Color.FromArgb(hsbRed.Value, hsbGreen.Value, hsbBlue.Value)
End Sub
Private Sub hsbBlue_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbBlue.Scroll
Me.BackColor = Color.FromArgb(hsbRed.Value, hsbGreen.Value, hsbBlue.Value)
End Sub
End Class
Label: VB.NET
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda