C# İLE ZAMAN AYARLI BİLGİSAYAR KAPATMA



Programda 3 farklı buton ve 3 label bulunmakta.Bunları açıklarsak saat,dakika ve saniyeden oluşuyor.İstedğiniz zamanı ayarlayıp eğer zaman ayarla butonuna basarak istediğiniz vakitte bilgisayarınızı kapatmak için ayarlayabilirsiniz.

Projenin kodları aşağıdaki gibirdir.

İlk olarak kütüphanenize şu kodu eklemeniz gerekmektedir.


using System.Diagnostics;


Ardından gelelim formdaki kodlarımıza :


private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "C:\\Windows\\system32\\shutdown.exe";
            psi.Arguments = "-f -s -t 0";
            Process.Start(psi);
        }

        

        private void timer1_Tick(object sender, EventArgs e)
        {

            string saat, dakika, saniye;
            saat = textBox1.Text;
            dakika = textBox2.Text;
            saniye = textBox3.Text;


            if ((Convert.ToString(DateTime.Now.Hour)) == saat && (Convert.ToString(DateTime.Now.Minute) == dakika) && (Convert.ToString(DateTime.Now.Second)) == saniye)
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = "C:\\Windows\\system32\\shutdown.exe";
                psi.Arguments = "-f -s -t 0";
                Process.Start(psi);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("shutdown", "-f -s");
        }

Yorumlar

Bu blogdaki popüler yayınlar

C# EntityFramework ve SQL Kullanarak Hastane Randevu Otomasyonu

C# RANDOM BİR ŞİFRE OLUŞTURMA