Tentang shareilmu2ilmu.blogspot.com

http://shareilmu2ilmu.blogspot.com/ adalah blog tentang komputer yang di buat untuk Pembelajaran, tugas-tugas,aplikasi komputer,Coding,pemograman visual, sistem manajemen basis data

Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Thursday, 17 January 2013

Turorial mebuat Datagridview C#

Tampilan awal.





Coding untuk frmPegawai.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frmPegawai : Form
    {
        public frmPegawai()
        {
            InitializeComponent();
        }


        private void frmPegawai_Load(object sender, EventArgs e)
        {
            dgPegawai.AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine;
        }

        private void cmdSimpan_Click(object sender, EventArgs e)
        {
            string[] row = { txtNIK.Text, txtNAMA.Text, txtALAMAT.Text };
            dgPegawai.Rows.Add(row);

            dgPegawai.AutoResizeColumns();
        }
        private void dgPegawai_CellEnter(object sender, EventArgs e)
        {
            txtNIK.Text = dgPegawai.CurrentRow.Cells[0].Value.ToString();
            txtNAMA.Text = dgPegawai.CurrentRow.Cells[1].Value.ToString();
            txtALAMAT.Text = dgPegawai.CurrentRow.Cells[2].Value.ToString();
        }

        private void cmdHapus_Click(object sender, EventArgs e)
        {

            dgPegawai.Rows.RemoveAt(dgPegawai.SelectedRows[0].Index);
        }

        private void cmdUbah_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgPegawai.Rows)
            {
                DataGridViewCell cell = row.Cells[0];
                cell.Value = txtNIK.Text;
            }


        }
    }
}








Ubah Button:


Hapus Button:



Wednesday, 9 January 2013

Membuat mp3 Player sederhana menggunakan c#



Tampilan Form:


Koding Program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace mp3_Player
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string[] files, paths;
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                files = openFileDialog1.SafeFileNames;
                paths = openFileDialog1.FileNames;
                for (int i = 0; i < files.Length; i++)
                {
                    listBox1.Items.Add(files[i]);
                }
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL = paths[listBox1.SelectedIndex];
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}



Out Put Tampilan :
Play.
Open.





Monday, 31 December 2012

Tutorial Menampilkan Gambar & Identitas Pada Form 2 C#

Gambar 0.1
Gambar 0.1 adalah tampilan pada form 1 yang berisikan coding sebagai berikut :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("Islam");
            comboBox1.Items.Add("Kristen");
            comboBox1.Items.Add("Katolik");
            comboBox1.Items.Add("Hindu");
            comboBox1.Items.Add("Budha");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string a, b, c, d, f;
            if (radioButton1.Checked == true)
            {
                a = "Laki-laki";
            }
             else
            {
                a = "Perempuan";
            }
            if (checkBox1.Checked == true)
            {
                b = "Sepak Bola";
            }
            else
            {
                b = "";
            }
            if (checkBox2.Checked == true)
            {
                c = "Badminton";
            }
            else
            {
                c = "";
            }
            if (checkBox3.Checked==true)
            {
                d = "Basket";
            }
            else
            {
                d="";
            }
            if (checkBox4.Checked==true)
            {
                f = "Volley";
            }
            else 
            {
                f="";
            }
            Form2 baru = new Form2();
            baru.richTextBox1.Text  
                = "\nNama\t\t: " + textBox1.Text + "\nAlamat\t\t: " + textBox2.Text +
                "\nJenis Kelamin\t: " + a + "\nHobi\t\t\t: " + b + c + d + f;
            baru.pictureBox1.Image = pictureBox1.Image;
            baru.Show();
            
        }
        private void tabPage2_Click(object sender, EventArgs e)
        {
        }
        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
        }
    }
}

Gambar 0.2
Pada Gambar 0.2 adalah tampilan form pada form 2,,jadi disini kita membuat form baru ,,dan akan menampilkannya pada form2 ,jadi kita menggabungkan 2 form dan ini kodingnya :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
        }
        private void Form2_Load(object sender, EventArgs e)
        {
        }
    }
}


Dan Gambar 0.3 adalah tampilan pada form1 bagian tab page .
Gambar 0.3

Dan Gambar 0.4 adalah Gambar Sebelum ditambahkannya gambar pada form 1 tab page 2 "
Gambar 0.4

Tuesday, 11 December 2012

Script windows form Pemesanan Tiket Kereta


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cmbkereta.Items.Add("Mutiara Timur");
            cmbkereta.Items.Add("Purwojaya");
            cmbkereta.Items.Add("Logawa");
        }

        private void cmdproses_Click(object sender, EventArgs e)
        {
            /*button proses*/
            int harga;

            double diskon, total;

            if (cmbkereta.SelectedItem.ToString() == "Mutiara Timur")
            {
                harga = 125000;
            }
            else if (cmbkereta.SelectedItem.ToString() == "purwojaya")
            {
                harga = 97500;
            }
            else
            {
                harga = 45000;
            }

            /*radio button menggunakan .Checked*/
            if (optkaryawan.Checked == true)
            {
                diskon = 0.1;
            }
            else
            {
                diskon = 0;
            }



            /*rumus*/
            total = (harga * double.Parse(txtjumlah.Text)) - (harga * double.Parse(txtjumlah.Text) * diskon);
            MessageBox.Show("Total Bayar = " + total.ToString());

            /*Checkbox*/
            if (checkBox1.Checked == true)
            {
                total = total + 3500;
            }
            else if (checkBox2.Checked == true)
            {
                total = total + 6000;
            }
            else
            {
                total = total + 12500;
            }

            MessageBox.Show("Total = " + total.ToString());

        }
    }
}

Sunday, 28 October 2012

Script C# penjumlahan matriks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            //DEKLARASI VARIABLE DAN ARRAY
            int a, b, i, j;
            int baris_a, kolom_a, baris_b, kolom_b;
            int[,] matrik_a;
            int[,] matrik_b;
            byte x;
            //INPUT JUMLAH BARIS DAN KOLOM
            Console.WriteLine();
            Console.Write("<-PROGRAM PENJUMLAHAN MATRIKS->");
            Console.WriteLine();
            Console.WriteLine();
            x = 1;
            while (x >= 1)
            {
                Console.Write("Jumlah Baris Matrik A : ");
                baris_a = int.Parse(Console.ReadLine());
                Console.Write("Jumlah Kolom Matrik A : ");
                kolom_a = int.Parse(Console.ReadLine());
                Console.Write("Jumlah Baris Matrik B : ");
                baris_b = int.Parse(Console.ReadLine());
                Console.Write("Jumlah Kolom Matrik B : ");
                kolom_b = int.Parse(Console.ReadLine());
                Console.WriteLine();
                if (baris_a == baris_b || kolom_a == kolom_b)
                {

                    //ISI ARRAY MATRIKS

                    matrik_a = new int[baris_a, kolom_a];
                    matrik_b = new int[baris_b, kolom_b];

                    Console.WriteLine(" Nilai Matriks A : ");
                    Console.WriteLine("--------------- ");
                    Console.WriteLine();
                    Console.WriteLine();
                    for (a = 0; a < baris_a; a++)
                    {
                        for (b = 0; b < kolom_a; b++)
                        {
                            Console.Write(" Matriks A [" +
                            (a + 1) + " , " + (b + 1) + " ] = ");

                            matrik_a[a, b] = int.Parse(Console.ReadLine());
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine(" Nilai Matriks B : ");
                    Console.WriteLine("--------------- ");
                    Console.WriteLine();
                    Console.WriteLine();
                    for (i = 0; i < baris_b; i++)
                    {
                        for (j = 0; j < kolom_b; j++)
                        {
                            Console.Write(" Matriks B [" + (i + 1) + " , " + (j + 1) + " ] = ");
                            matrik_b[i, j] = int.Parse(Console.ReadLine());
                        }
                    }


                    //HASIL JUMLAH MATRIK A & B
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine(" HASIL PENJUMLAHAN MATRIKS A & B =");
                    Console.WriteLine("------------------------------------ ");
                    Console.WriteLine();
                    for (a = 0; a < baris_a; a++)
                    {
                        for (b = 0; b < kolom_a; b++)
                        {
                            Console.Write(matrik_a[a, b] + matrik_b[a, b]
                            + " ");
                        }
                        Console.WriteLine();
                    }

                    {

                        Console.ReadKey();
                        break;
                    }

                }
                Console.ReadLine();
            }

        }


    }
}