• Demo Hẹn giờ tắt Máy tính
  • Demo Hẹn giờ tắt Máy tính

    maidinhdan > 24-04-20, 08:33 PM

    Chức năng Hẹn giờ tắt hoặc khởi động lại Máy tính.



    Tác giả: Chính chủ. Ứng dụng không cá nhân hóa, không ghi bất kỳ thông tin gì, nên cứ dùng thoải mái. Có thể tặng bàn bè nói là mình viết cũng được.

    Ứng dụng không cần cài đặt, bật lên là dùng.

    Ngôn ngữ: VB.Net ( Được viết trên Visual Studio 2008 - 2010)
    NetFrameWork: 2.0


    Hình minh họa

    [Hình: HinhDemoTatmaytinh.png]



    Code:

    Mã:
    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 DemoTatmaytinh

    {

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }



            int Sogiayconlai;



            private void Form1_Load(object sender, EventArgs e)

            {

                timer2.Interval = 1000;

                timer2.Enabled = true;

                txtSophut.Select();

            }



            private void btnThuchien_Click(object sender, EventArgs e)

            {

                timer1.Interval = 1000;

                timer1.Enabled = true;

                Sogiayconlai = 0;

                Sogiayconlai = int.Parse(txtSophut.Text) * 60;

                btnThuchien.Enabled = false;



            }



            private void timer1_Tick(object sender, EventArgs e)

            {

                if(Sogiayconlai>0)

                {

                    lblNhapphut.Text="Máy tính sẽ tắt sau...";

                    txtSophut.Text = Sogiayconlai + " giây";

                    Sogiayconlai = Sogiayconlai - 1;

                }

                else

                {

                    timer1.Stop();

                    timer1.Enabled=false;

                    //Check bok khởi động lại hay tắt máy

                    if (cbkKhoidonglai.Checked==false)

                    {

                        System.Diagnostics.Process.Start("shutdown", "-s -f -t 0");// shutdown

                    }

                    else

                    {

                        lblNhapphut.Text = "Máy tính sẽ khởi động lại sau...";

                    System.Diagnostics.Process.Start("shutdown", "-r -f -t 0");//restart

                    }

                    //Thoát chương trình

                    Application.Exit();

                   

                }

            }



            private void timer2_Tick(object sender, EventArgs e)

            {

                this.Text = "Hẹn giờ tắt máy tính, [Giờ hiện tại: " + DateTime.Now.ToLongTimeString() +"]";

            }



            private void btnThoat_Click(object sender, EventArgs e)

            {

                DialogResult Xacnhan = MessageBox.Show("Bạn có muốn thoát khỏi chương trình không", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);



                if(Xacnhan==DialogResult.OK)

                {

                    //Cho thoat

                    Application.Exit();

                }



               

            }



        }

    }





    Demo Ứng dụng: Đính kèm.

    Ai cần Source gốc xin để lại Email.