Senin, 15 Mei 2017

Membuat Program C# Stopwatch

Tampilan :


Table komponen

Stopwatch




Tampilan Program :

Tampilan awal

Setelah tombol Start di klik




Setelah tombol Stop di klik



Setelah tombol Resume di klik

Setelah tombol Restart di klik




 Setelah tombol Reset di klik




Codingan Stopwatch :

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;
//tambahkan
using System.Diagnostics;

namespace Stopwatchproj
{
    public partial class Form1 : Form
    {
        private Stopwatch stopw = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (stopw != null)
            {
                label1.Text = stopw.Elapsed.ToString(@"hh\:mm\:ss\:ff");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "Start")
            {
                stopw = new Stopwatch();
                stopw.Start();
                button1.Enabled = false;
                button2.Enabled = true;
            }
            else if (button1.Text == "Restart")
            {
                stopw.Restart();
                button1.Enabled = false;
                button2.Text = "Stop";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (button2.Text == "Stop")
            {
                stopw.Stop();
                button1.Text = "Restart";
                button1.Enabled = true;
                button2.Text = "Resume";
            }
            else if (button2.Text == "Resume")
            {
                stopw.Start();
                button1.Enabled = false;
                button2.Text = "Stop";
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            stopw.Reset();
            button1.Enabled = true;
            button1.Text = "Start";
            button2.Text = "Stop";
            button2.Enabled = false;
        }

    }
}

SEMOGA BERMANFAAT :)

Membuat Program C# Notepad

Tampilan :



















Codingan Notepad :

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;
using Microsoft.Win32; //library tambahan
using System.IO; //dalam program windows 32


namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen; //posisi form berada di tengah,
            this.FormBorderStyle = FormBorderStyle.FixedSingle; // form tidak bisa dibesar / dikecilkan
            this.MaximizeBox = false; //dan menghilangkan tombol maximize dan minimize.
            this.MaximizeBox = false;
        }

        void bersih()  // fungsi untuk membersihkan richtext input
        {
            rtinput.Text = "";

        }
        void bukafile() //funsi untuk membuka file ".txt"
        {
            bersih();
            OpenFileDialog buka = new OpenFileDialog();
            buka.DefaultExt = ".txt";
            buka.Filter = " Text Documents | *.txt";
            buka.FileName = "";

            if (buka.ShowDialog() != DialogResult.Cancel)
            {
                string fileterpilih = buka.FileName;
                if (fileterpilih != "")
                {
                    rtinput.LoadFile(fileterpilih, RichTextBoxStreamType.PlainText);
                }

            }
        }
        void simpanfile() // fungsi untuk menyimpan file
        {
            SaveFileDialog simpan = new SaveFileDialog();
            simpan.Filter = " text document | *.txt";
            simpan.RestoreDirectory = true;
                if (simpan.ShowDialog() != DialogResult.Cancel)
                {
                    StreamWriter filesimpan = new StreamWriter(File.Create(simpan.FileName));
                    filesimpan.Write(rtinput.Text);
                    filesimpan.Dispose();
                }

        }
    
        
        private void bbukafile_Click(object sender, EventArgs e)
        {
        if (rtinput.Text != "")
        {
            var pesan = MessageBox.Show("File belum tersimpan, yakin ingin membuka file baru ???","konfirmasi",MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (pesan == DialogResult.Yes)
            {
                bukafile();
            }
        }
            else
        {
            bukafile();
        }
        }

        private void bsimpan_Click(object sender, EventArgs e)
        {
            {
                simpanfile();
            }
        }

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

        private void rtinput_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            rtinput.SelectionFont = new Font(rtinput.Font, FontStyle.Italic);
            rtinput.SelectionStart = rtinput.SelectionStart + rtinput.SelectionLength;
            rtinput.SelectionLength = 0;
            rtinput.SelectionFont = rtinput.Font;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            rtinput.SelectionFont = new Font(rtinput.Font, FontStyle.Bold);
            rtinput.SelectionStart = rtinput.SelectionStart + rtinput.SelectionLength;
            rtinput.SelectionLength = 0;
            rtinput.SelectionFont = rtinput.Font;
        }

        private void undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rtinput.CanUndo == true)
            {
                rtinput.Undo();
            }
        }

        private void redoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rtinput.CanRedo == true)
            {
                rtinput.Redo();
            }
        }

        private void copyToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (rtinput.SelectedText != "")
            {
                rtinput.Copy();
            }
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
             rtinput.Paste();
        }

        private void italicToolStripMenuItem_Click(object sender, EventArgs e)
        {
            rtinput.SelectionFont = new Font(rtinput.Font, FontStyle.Italic);
            rtinput.SelectionStart = rtinput.SelectionStart + rtinput.SelectionLength;
            rtinput.SelectionLength = 0;
            rtinput.SelectionFont = rtinput.Font;
        }

      
        }
    }

SEMOGA BERMANFAAT :)

Membuat Program C# Billing


Desain :


Billing


Table Layout Objek










Dan berikut adalah kodingan nya:

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;
using System.Diagnostics;

namespace Aplikasi_Billing_Paket
{
    public partial class Form1 : Form
    {
        private Stopwatch wkt = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                wkt = new Stopwatch();
                if (button1.Text == "LOGIN")
                {
                    if (radioButton1.Checked)
                    {
                        label10.Text = "1 jam";
                    }
                    else if (radioButton2.Checked)
                    {
                        label10.Text = "2 jam";
                    }
                    else if (radioButton3.Checked)
                    {
                        label10.Text = "3 jam";
                    }
                    else if (radioButton4.Checked)
                    {
                        label10.Text = "4 jam";
                    }
                    label3.Visible = true;
                    wkt.Start();
                    button1.Text = "STOP";
                    label10.Visible = true;
                    button1.Text ="STOP";
                }
                else if (button1.Text == "STOP")
                {

                    wkt.Start();
                    if (radioButton1.Checked)
                    {
                        MessageBox.Show("Jumlah tagihan anda sebesar Rp 2000", "Total Tagihan Paket Regular");
                    }
                    if (radioButton2.Checked)
                    {
                        MessageBox.Show("Jumlah Tagihan anda sebesar Rp 3000", "Total Tahihan Paket Hemat");
                    }
                    if (radioButton3.Checked)
                    {
                        MessageBox.Show("Jumlah Tagihan anda sebesar Rp 4000", "Total Tahihan Paket Game 1");
                    }
                    if (radioButton4.Checked)
                    {
                        MessageBox.Show("Jumlah Tagihan anda sebesar Rp 5000", "Total Tahihan Paket Game 2");
                    }
                    wkt.Reset();
                    label3.Visible = false;
                    button1.Text = "LOGIN";
                    textBox1.Text = null;
                    label10.Visible = false;
                    button1.Text = "LOGIN";

                }
            }

            else if (textBox1.Text == "")
            {
                MessageBox.Show("Nama Harus Diisi!!!", "Important Message");
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (wkt != null)
            {
                label3.Text = wkt.Elapsed.ToString(@"hh\:mm\:ss");
            }
        }

    }
}

SEMOGA BERMANFAAT :)