* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
2.7 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|
| Power Management | 03/30/2017 |
|
|
ad04a801-5682-4d88-92c5-26eb9cdb209a |
Power Management in Windows Forms
Your Windows Forms applications can take advantage of the power management features in the Windows operating system. Your applications can monitor the power status of a computer and take action when a status change occurs. For example, if your application is running on a portable computer, you might want to disable certain features in your application when the computer's battery charge falls under a certain level.
The .NET Framework provides a xref:Microsoft.Win32.SystemEvents.PowerModeChanged event that occurs whenever there is a change in power status, such as when a user suspends or resumes the operating system, or when the AC power status or battery status changes. The xref:System.Windows.Forms.SystemInformation.PowerStatus%2A property of the xref:System.Windows.Forms.SystemInformation class can be used to query for the current status, as shown in the following code example.
[!code-csharpPowerMode#1] [!code-vbPowerMode#1]
Besides the xref:System.Windows.Forms.BatteryChargeStatus enumerations, the xref:System.Windows.Forms.SystemInformation.PowerStatus%2A property also contains enumerations for determining battery capacity (xref:System.Windows.Forms.PowerStatus.BatteryFullLifetime%2A) and battery charge percentage (xref:System.Windows.Forms.PowerStatus.BatteryLifePercent%2A, xref:System.Windows.Forms.PowerStatus.BatteryLifeRemaining%2A).
You can use the xref:System.Windows.Forms.Application.SetSuspendState%2A method of the xref:System.Windows.Forms.Application to put a computer into hibernation or suspend mode. If the force argument is set to false, the operating system will broadcast an event to all applications requesting permission to suspend. If the disableWakeEvent argument is set to true, the operating system disables all wake events.
The following code example demonstrates how to put a computer into hibernation.
[!code-csharpPowerMode#2] [!code-vbPowerMode#2]