1. Buka VS 12. File > New > Project (Ctrl+Shift+N)

2. Pilih Visual C# yang ada di tab sebelah kiri. Windows > Windows Form Application. Ubah Nama serta location sesuai yang diinginkan. Klik OK.
3. Maka akan tampil sebagai gambar dibawah ini. Ubah Nama Form dengan mengubah Text di tab properties yang ada di pojok kanan bawah menjadi Validation Form.
4. Buka Toolbox dengan menekan Ctrl+Alt+X.Insert Toolbox yang ada di All Windows Forms (Label, TextBox, Button, Progress Bar, Error Provider). Susun seperti gambar. Untuk text, dan nama dapat dirubah di tab properties.
5. Klik kanan pada form dan pilih view code.

6. Ketikkan script berikut pada workspace.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
bar1.Value = 0;
if (txtNama.Text == "")
{
x.SetError(txtNama, "Masukkan Nama");
}
else
{
x.SetError(txtNama, "");
}
if (txtNIS.Text == "")
{
x1.SetError(txtNIS, "Masukkan NIS");
}
else
{
x1.SetError (txtNIS , "");
}
if (txtKelas.Text == "")
{
x2.SetError(txtKelas, "Masukkan Kelas");
}
else
{
x2.SetError(txtKelas, "");
}
if (txtSMP.Text == "")
{
x3.SetError(txtSMP, "Masukkan SMP Asal");
}
else
{
x3.SetError(txtSMP, "");
}
for (int i = 0; i < bar1.Maximum; i++)
{
bar1.Value = bar1.Value + 1;
}
MessageBox.Show("\nNama\t : " + txtNama.Text + "\nNIS\t : " + txtNIS.Text + "\nKelas\t : " + txtKelas.Text + "\nSMP Asal\t : " + txtSMP.Text);
}
}
}
7. Jalankan program dengan mengklik start, maka akan muncul sebagai berikut.

Jika data sudah terisi, klik tombol eksekusi dan kemudian akan muncul hasil sebagai berikut.







Tidak ada komentar:
Posting Komentar