📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
namespace Power
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmPowerDemo : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox rtfList;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmPowerDemo()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//Register for power change updates
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.rtfList = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// rtfList
//
this.rtfList.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtfList.Location = new System.Drawing.Point(4, 4);
this.rtfList.Name = "rtfList";
this.rtfList.Size = new System.Drawing.Size(284, 105);
this.rtfList.TabIndex = 0;
this.rtfList.Text = "";
//
// frmPowerDemo
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 113);
this.Controls.Add(this.rtfList);
this.DockPadding.All = 4;
this.Name = "frmPowerDemo";
this.Text = "PowerDemo - Now Suspend/Hibernate/Resume and pull out the plug";
this.Closed += new System.EventHandler(this.frmPowerDemo_Closed);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmPowerDemo());
}
#region Suspend/Hibernate/Standby
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
switch (e.Mode)
{
case PowerModes.Suspend:
rtfList.Text = DateTime.Now.ToLongTimeString() +": Suspending\n" + rtfList.Text;
break;
case PowerModes.Resume:
rtfList.Text = DateTime.Now.ToLongTimeString() +": Resuming\n" + rtfList.Text;
break;
case PowerModes.StatusChange:
PowerStatus ps = new PowerStatus();
rtfList.Text = DateTime.Now.ToLongTimeString()
+"- ACLine:"+ps.ACLineStatus.ToString()
+" BatteryFlag:"+ps.BatteryFlag.ToString()
+" BatteryFullLifeTime:" + ps.BatteryFullLifeTime.ToString()
+ " BatteryLifePercent:" + ps.BatteryLifePercent.ToString()
+ "% BatteryLifeTime:" + ps.BatteryLifeTime.ToString()
+"\n"+ rtfList.Text;;
break;
}
}
#endregion
//Save the file on final closure
private void frmPowerDemo_Closed(object sender, System.EventArgs e)
{
rtfList.SaveFile(Application.UserAppDataPath+"\\PowerDemo.txt");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -