using System.Windows.Forms;
namespace ProductManager
{
public partial class FormPowerState : Form
{
public FormPowerState()
{
#region
InitializeComponent();
this.ShowInTaskbar = false; // 禁止在 Windows 任务栏中显示窗体。
this.StartPosition = FormStartPosition.CenterParent;
DateTime newTime = DateTime.Now;
labelTime.Text = string.Format("{0:HH:mm:ss}", newTime);
numericHour.Value = newTime.Hour;
numericMinute.Value = newTime.Minute;
#endregion
}
#region TimeSpan
private void timerPower_Tick(object sender, EventArgs e)
{
labelTime.Text = string.Format("{0:HH:mm:ss}", DateTime.Now);
if (btnOK.Enabled)
return;
string newTime = string.Format("{0:00}:{1:00}:00", numericHour.Value, numericMinute.Value);
TimeSpan newSpan = DateTime.Parse(newTime).Subtract(DateTime.Now);
switch ((int)Math.Ceiling(newSpan.TotalSeconds))
{
case 30:
this.Show();
this.Activate();
Console.Beep();
break;
case 0:
Application.SetSuspendState(PowerState.Suspend, true, false);
this.Close();
break;
}
}
#endregion
#region OKButton
private void btnOK_Click(object sender, EventArgs e)
{
btnOK.Enabled = false;
this.Close();
}
#endregion
#region CancelButton
private void btnCancel_Click(object sender, EventArgs e)
{
DateTime newTime = DateTime.Now;
numericHour.Value = newTime.Hour;
numericMinute.Value = newTime.Minute;
btnOK.Enabled = true;
this.Close();
}
#endregion
#region FormClosing
private void FormPowerState_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.ApplicationExitCall)
{
this.Hide();
e.Cancel = true;
}
}
#endregion
}
}