Praktikum ASP 4

kalau di Praktikum ASP 3 kita masih menggunakan Console Application,, kali ini di Praktikum ASP 4 kita bakalan menggunakan Windows Forms Application, dan bermain-main dengan Form. Nah ini langkah-langkah pembuatan progamnya :



  • Dengan menggunakan software Visual Studio Ultimate 2012, buka New Project
  •  Pilih Visual C# -> Windows -> Windows Form Application
  • Beri Nama Project/Solution Name -> ASP04 (isikan bebas)
  • Klik OK
  •  Kemudian masukkan Tool - tool berikut : Seperti Label, Button, ErrorProvider, ProgessBar, TextBox
  • Kemudian Susun hingga seperti gambar :
  • Kemudian Masuk ke Form1.cs, ketikkan Script berikut :
    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 FormVal
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

          

            private void Form1_Load(object sender, EventArgs e)
            {
            }

            private void button2_Click(object sender, EventArgs e)
            {
                bar1.Value = 0;


                if (a.Text == "")
                {
                    x.SetError(a, "Nama");
                }
                else
                {
                    x.SetError(a, "");
                }

                if (b.Text == "")
                {
                    x1.SetError(b, "Nama");
                }
                else
                {
                    x1.SetError(b, "");
                }

                if (c.Text == "")
                {
                    x2.SetError(c, "Nama");
                }
                else
                {
                    x2.SetError(c, "");
                }

                if (d.Text == "")
                {
                    x3.SetError(d, "Nama");
                }
                else
                {
                    x3.SetError(d, "");
                }

                if (a.Text == "" )
                {
                    x.SetError(a, "Masukan nama");
                    MessageBox.Show("Data kurang Lengkap, Lengkapi namamu!");
                    for (int i = 0; i < bar1.Maximum; i++)
                    {
                        bar1.Value = bar1.Value + 1;
                    }


                }
                else
                {
                    if (b.Text == "")
                    {
                        x1.SetError(b, "Masukan NIS");
                        MessageBox.Show("Data kurang Lengkap, Lengkapi NIS!");
                        for (int i = 0; i < bar1.Maximum; i++)
                        {
                            bar1.Value = bar1.Value + 1;
                        }
                    }
                    else
                    {
                        if (c.Text == "")
                        {
                            x2.SetError(c, "Masukan Kelas");
                            MessageBox.Show("Data kurang Lengkap, Lengkapi Kelas!");
                            for (int i = 0; i < bar1.Maximum; i++)
                            {
                                bar1.Value = bar1.Value + 1;
                            }
                        }
                        else
                        {
                            if (d.Text == "")
                            {
                                x3.SetError(d, "Masukkan SMP");
                                MessageBox.Show("Data kurang Lengkap, Lengkapi Asal SMP");
                                for (int i = 0; i < bar1.Maximum; i++)
                                {
                                    bar1.Value = bar1.Value + 1;
                                }
                            }
                        }
                      
                    }

                }
                     
                if (d.Text != "" && a.Text !="" && c.Text !="" && b.Text !="")
                {
                    for (int i = 0; i < bar1.Maximum; i++)
                    {
                        bar1.Value = bar1.Value + 1;
                    }
                    MessageBox.Show("\nNama\t : " + a.Text + "\nNIS\t : " + b.Text + "\nKelas\t : " + c.Text + "\nAsal SMP\t : " + d.Text);
                }
            }

       

            private void b_KeyPress(object sender, KeyPressEventArgs e)
            {
                const char Delete = (char)8;
                e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
            }

            private void button1_Click_1(object sender, EventArgs e)
            {
                a.ResetText();
                b.ResetText();
                c.ResetText();
                d.ResetText();
                bar1.Value = 0;
                x.SetError(a, "");
                x1.SetError(b, "");
                x2.SetError(c, "");
                x3.SetError(d, "");
            }

            private void a_TextChanged(object sender, EventArgs e)
            {

            }
        }
    }
  • Setelah itu coba tekan CTRL + F5
  • Maka hasilnya akan seperti ini :
  • Selamat Mencoba dan Selamat Bereksperimen sendiri :D Semoga Berhasil.. :P

Komentar

Postingan Populer