Selasa, 20 Maret 2018

TUTORIAL MEMBUAT SHUTDOWN MANAGER DENGAN TIMER COUNTDOWN DI C#.

TUTORIAL MEMBUAT SHUTDOWN MANAGER DENGAN TIMER COUNTDOWN DI C#.





1. Buka Application  Microsoft Visual Studio.
2.Pilih New > File > Project.


3.Pilih "Windows Forms Application" dan beri namanya. Kemudian pilih "OK".




4. Komponen yang digunakan :



5.Desain Form dengan memasukkan semua component hingga seperti di bawah ini dan ubah nama form menjadi "Shutdown Manager".



6.Pada comboBox1, kita bisa isikan perintah yang akan dieksekusi oleh program. kita bisa klik comboBox dan pilih "Edit items" atau pilih properties yang ada disebelah kanan aplikasi dan klik "..." disamping tabel |Items |(Collection).


Setelah kita isi seperti pada gambar diatas ini, pilih "OK".





7.Masuk ke bagian Form1.cs

Masukkan Coding

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;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace Shutdown_Manager
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
        
        int hours, mins, secs;
        String shutdown;

--------------------------------------------------------------------------------------------------------------------------

7A. Coding button1 :

private void button1_Click(object sender, EventArgs e)
        {
            hours = int.Parse(textBox2.Text);
            mins = int.Parse(textBox3.Text);
            secs = int.Parse(textBox4.Text);
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            button1.Enabled = false;
            Process.Start("Shutdown", shutdown + " -t ");
            timer1.Start();
RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);      reg.SetValue("My Application", Application.ExecutablePath.ToString());
MessageBox.Show("The Computer will shut down immediately.", "Shutdown", MessageBoxButtons.OK, MessageBoxIcon.Information); 
 }

--------------------------------------------------------------------------------------------------------------------------

7B. Coding button2 :

private void button2_Click(object sender, EventArgs e)
        {

            button1.Enabled = true;
            Process.Start("Shutdown", "-a");
            timer1.Stop();
            textBox1.Clear();
            textBox2.Clear();           
            textBox3.Clear();
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            labelHour.Text = "00";
            labelMin.Text = "00";
            labelSec.Text = "00";
        }

--------------------------------------------------------------------------------------------------------------------------

7C. Coding comboBox1 :

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0: shutdown = "-s"; break;
                case 1: shutdown = "-r"break;
                case 2: shutdown = "-l"break;
            }
        }

--------------------------------------------------------------------------------------------------------------------------

7D. Coding timer1 :

private void timer1_Tick(object sender, EventArgs e)
        {
            {
               if (secs < 1)
                {
                    secs = 59;
                    if (mins < 1)
                    {
                        mins = 59;
                        if (hours != 0)
                            hours -= 1;
                    }
                    else mins -= 1;

                }
                else secs -= 1;
                if (hours > 9)
                    labelHour.Text = hours.ToString();
                else labelHour.Text = "0" + hours.ToString();

                if (mins > 9)
                    labelMin.Text = mins.ToString();
                else labelMin.Text = "0" + mins.ToString();

                if (secs > 9)
                    labelSec.Text = secs.ToString();
                else labelSec.Text = "0" + secs.ToString();
                
            }
            
        }
       
    }
}

--------------------------------------------------------------------------------------------------------------------------

8.Setelah semua Coding dimasukkan, mulai running program. klik icon "➤" pada toolbar atau F5 pada keyboard.


-Masukkan durasi pada textbox1, textbox2, textbox 3. contoh "01, 02, 03, dst."
-Pilih perintah apa yang akan dieksekusi pada tabel comboBox " Shutdown, Restart, Log off".
-klik button "Start" untuk memulai eksekusi perintah.
-klik button "Abort" untuk membatalkan eksekusi perintah.

9.Setelah Running selesai, buka regedit dan mengecek registry key apakah sudah masuk untuk menampilkan Aplikasi Autorun saat windows mulai dinyalakan.

10. Pilih HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Run.



11.Running Program.

-Versi Blog :

-Versi Youtube :

https://youtu.be/0Iw6FcoBS7g


Tidak ada komentar:

Posting Komentar