12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Windows.Forms;
- using Microsoft.Win32;
- using TurnoffMonitorOnLock.IconExtract;
- using TurnoffMonitorOnLock.MonitorPowerApi;
- namespace TurnoffMonitorOnLock
- {
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
- var eIcon = IconExtractor.GetMainIcon();
- if (null != eIcon)
- {
- Icon = eIcon;
- MinisizeToTray.Icon = eIcon;
- }
- SystemEvents.SessionSwitch += delegate (object o, SessionSwitchEventArgs args)
- {
- if (args.Reason == SessionSwitchReason.SessionLock)
- MonitorPower.SetMonitorInState(MonitorState.MonitorStateOff);
- };
- }
- private void MainForm_Shown(object sender, System.EventArgs e)
- {
- if (Program.CommandLineArgs.Count != 0) WindowState = FormWindowState.Minimized;
- }
- private void MainForm_Resize(object sender, System.EventArgs e)
- {
- if (WindowState != FormWindowState.Minimized) return;
- Hide();
- MinisizeToTray.Visible = true;
- MinisizeToTray.ShowBalloonTip(5000, Text, "Im here", ToolTipIcon.Info);
- }
- private void MinisizeToTray_Click(object sender, System.EventArgs e)
- {
- MinisizeToTray.Visible = false;
- Show();
- WindowState = FormWindowState.Normal;
- }
- }
- }
|