Kamis, 19 Desember 2013

Modifikasi Aplikasi “Hello, World!” dengan menambah kontrol secara dinamis pada saat di jalankan di Visual Basic.NET 2010

Hello_World_modif.NET

Setelah pada posting sebelumnya saya membuat memodifikasi aplikasi “Hello, World!” pada Visual Basic 6.0 kini saya akan beralih pada Visual Basic.NET pada postingan ini saya mencoba beberapa modifikasi seperti modifikasi yang saya terapkan pada postingan saya sebelumnya. Sekali lagi saya berharap percontohan ini dapat memberikan gambaran lebih lanjut kepada teman-teman mengenai metode menambah kontrol secara dinamis pada saat aplikasi.di jalankan khususnya pada Visual Basic.NET 2010

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

Start Page VB.NET Crop

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

New Project VB.NET

4. Lalu pada jendela “Solution Explorer” yang berada pada pojok kanan atas, pilih “View Code

Solution Explorer VB.NET

5. Setelah jendela “Form1.vb” terbuka copy semua listing code di bawah ini kemudian paste-kan di sana

 

Public Class Form1
Dim cmdClickHere As New Button
Dim lblName As New Label
Dim txtName As New TextBox
Dim cmdExit As New Button

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With Me
.Text = "Hello World"
.CenterToScreen()
.MaximizeBox = False
.MinimizeBox = False
.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle

.Controls.Add(cmdClickHere)
.Controls.Add(lblName)
.Controls.Add(txtName)
.Controls.Add(cmdExit)
End With

With cmdClickHere
.Text = "Click Here"
.Location = New Point(Me.Size.Width - 236, Me.Size.Height - 171)
.Size = New Size(.Size.Width + 97, .Size.Height)
.TabIndex = 2
.Enabled = False
End With

With lblName
.Text = "Type Your Name:"
.Location = New Point(Me.Size.Width - 240, Me.Size.Height - 220)
.TabIndex = 0
.AutoSize = True
End With

With txtName
.Text = ""
.Location = New Point(Me.Size.Width - 236, Me.Size.Height - 204)
.Size = New Size(.Size.Width + 70, .Size.Height)
.TabIndex = 1
.Font = New Font("Microsoft Sans Serif", 12)
.Focus()
End With

With cmdExit
.Text = "E&xit"
.Location = New Point(Me.Size.Width - 236, Me.Size.Height - 138)
.Size = New Size(.Size.Width + 97, .Size.Height)
.TabIndex = 3
End With

AddHandler cmdClickHere.Click, AddressOf cmdClickHere_Click
AddHandler cmdExit.Click, AddressOf cmdExit_Click
AddHandler txtName.TextChanged, AddressOf txtName_TextChanged
AddHandler txtName.KeyPress, AddressOf txtName_KeyPress
End Sub

Private Sub cmdClickHere_Click(ByVal sender As Object, ByVal e As EventArgs)
If cmdClickHere.Text = "Click Here" Then
MsgBox("Hello, " + txtName.Text, MsgBoxStyle.Information, "Information")
Me.Text = "Hello, " + txtName.Text
cmdClickHere.Text = "New"
ElseIf cmdClickHere.Text = "New" Then
txtName.Text = ""
txtName.Focus()
cmdClickHere.Text = "Click Here"
Me.Text = "Hello World"
End If
End Sub

Private Sub cmdExit_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Response = MsgBox("Close the program", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirmation")

If Response = MsgBoxResult.Yes Then
End
End If
End Sub

Private Sub txtName_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
cmdClickHere.Enabled = True

If txtName.Text = "" Then
cmdClickHere.Enabled = False
End If
End Sub

Private Sub txtName_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If e.KeyChar = ChrW(Keys.Enter) Then
cmdClickHere_Click(sender, New EventArgs())
End If
End Sub
End Class



 


6. Setelah itu klik tombol “Start Debugging” pada “Command Bar” atau bisa juga menekan tombol “F5” pada keyboard


Start Debuging VB.NET

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda