分类:
2008-10-15 13:52:58
控件名 | 类别 | Text | 控件名 | 类别 | Text |
CheckBox1 | CheckBox | 自动关机 | GrouPBox1 | GroupBox | 当前系统时间 |
CheckBox1 | CheckBox | 倒计时执行操作 | GroupBox2 | GroupBox | 设定时间 |
CheckBox1 | CheckBox | 定时报警 | TxtTime | TextBox | |
ButCancle | Button | 取消 | SetupTime | DateTimePicker | |
ButReOpen | Button | 重新启动 | SetupDate | DateTimePicker | |
ButClose | Button | 关机 | Timer1 | Timer | 100 |
ButSysInto | Button | 系统信息 | ButReLogin | Button | 注消 |
using System.Runtime.InteropServices ; using System.Text ; |
[ DllImport("user32") ] public static extern long SetWindowPos(long hwnd , long hWndInsertAfter, long X , long y , long cx, long cy, long wFlagslong) ; |
[ DllImport("user32") ] public static extern long ExitWindowsEx(long uFlags, long dwReserved ) ; [ DllImport("shell32") ] public static extern long ShellAbout(long uFlags, long dwReserved ) ; |
long dwReserved ; const int SHUTDOWN = 1 ; const int REBOOT = 2 ; const int LOGOFF = 0 ; long sh ; int counter , n ; |
private void frmmain1_Load(object sender, System.EventArgs e ) { file://用系统时间初始化组件 Time.Text = System.DateTime.Today.ToShortDateString( ) + " "+ System.DateTime.Today.ToLongTimeString( ) ; } 在组件Timer1的OnTimer事件过程中编写如下代码: / / 在组件Timer1的OnTimer事件过程中编写如下代码: private void Timer1_Timer(object sender, System.EventArgs e ) { file://接收当前日期和时间,用于即时显示 string CurrDate=System.DateTime.Today.ToShortDateString( ) ; string CurrTime=System.DateTime.Today.ToShortTimeString( ) ; file://随时检测设定的关机日期和时间是否有效 if( this.CheckBox1.Checked == true ) { if(CurrDate== SetupDate.ToString( ) && CurrTime==SetupTime.ToString( ) ) ColseComputer( ) ; } } private void ColseComputer( ) { sh = ExitWindowsEx(SHUTDOWN, dwReserved) ; } private void button1_Click(object sender, System.EventArgs e ) { Form2 frm=new Form2( ) ; frm.Show( ) ; } private void ButReOpen_Click(object sender, System.EventArgs e ) { sh = ExitWindowsEx(REBOOT, dwReserved) ; } private void ButReLogin_Click(object sender, System.EventArgs e ) { sh = ExitWindowsEx(LOGOFF, dwReserved) ; } private void ButCancle_Click(object sender, System.EventArgs e ) { this.Close( ) ; } private void ButClose_Click_1(object sender, System.EventArgs e ) { sh = ExitWindowsEx(REBOOT, dwReserved) ; } |
[1]