/[NexusPowerControl]/trunk/NexusPowerControl/MainUI.cs
ViewVC logotype

Contents of /trunk/NexusPowerControl/MainUI.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (show annotations) (download)
Tue Oct 25 07:48:20 2011 UTC (7 years, 10 months ago) by william
File size: 5812 byte(s)
Turn off these defines: (testing is completed)
#define TEST_NEXUS_POWER_COMMAND
#define DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND

1 //#define TEST_NEXUS_POWER_COMMAND // when defined will, run the NexusPowerCommand in normal, non-hidden mode
2 //#define DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND // when defined, will not close the main form, when executing NexusPowerCommand operation
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Linq;
9 using System.Text;
10 using System.Windows.Forms;
11 using System.Diagnostics;
12
13 namespace NexusPowerControl
14 {
15 public partial class MainUI : Form
16 {
17 MouseTrapper mouse_trapper = new MouseTrapper();
18 public MainUI()
19 {
20 InitializeComponent();
21 }
22
23 private void Form1_Load(object sender, EventArgs e)
24 {
25 // load theme
26 ThemeLoader loader = new ThemeLoader();
27 loader.LoadThemeOrDefault(NexusPowerControl.Properties.Settings.Default.ActiveThemeName);
28 ThemeLoader.ThemeDefinition theme = loader.GetLoadedTheme();
29
30 if (theme.ThemeLoaded)
31 {
32 pic_main.Image = Image.FromFile(theme.MainImage);
33 btnShutdown.Image = Image.FromFile(theme.ShutdownImage);
34 btnRestart.Image = Image.FromFile(theme.RestartImage);
35 btnLogoff.Image = Image.FromFile(theme.LogoffImage);
36 btnLockScreen.Image = Image.FromFile(theme.LockScreenImage);
37 btnSleep.Image = Image.FromFile(theme.SleepImage);
38 btnClose.Image = Image.FromFile(theme.CloseImage);
39 }
40 else
41 {
42 pic_main.Image = ThemeConstants.Resources.DefaultThemeImages.MainImage;
43 btnShutdown.Image = ThemeConstants.Resources.DefaultThemeImages.ShutdownImage;
44 btnRestart.Image = ThemeConstants.Resources.DefaultThemeImages.RestartImage;
45 btnLogoff.Image = ThemeConstants.Resources.DefaultThemeImages.LogoffImage;
46 btnLockScreen.Image = ThemeConstants.Resources.DefaultThemeImages.LockScreenImage;
47 btnSleep.Image = ThemeConstants.Resources.DefaultThemeImages.SleepImage;
48 btnClose.Image = ThemeConstants.Resources.DefaultThemeImages.CloseImage;
49 }
50
51
52 btnShutdown.OnClickEvent += new EventHandler(btnShutdown_Click);
53 btnRestart.OnClickEvent += new EventHandler(btnRestart_Click);
54 btnLogoff.OnClickEvent += new EventHandler(btnLogoff_Click);
55 btnLockScreen.OnClickEvent += new EventHandler(btnLockScreen_Click);
56 btnSleep.OnClickEvent += new EventHandler(btnSleep_Click);
57 btnClose.OnClickEvent += new EventHandler(btnClose_Click);
58 }
59 private void MainUI_Shown(object sender, EventArgs e)
60 {
61 mouse_trapper.TrapMouse(this);
62 }
63
64 private void MainUI_FormClosed(object sender, FormClosedEventArgs e)
65 {
66 mouse_trapper.ReleaseMouse(this);
67 }
68 private void btnShutdown_Click(object sender, EventArgs e)
69 {
70 // shutdown the computer
71 Process p = new Process();
72 p.StartInfo.FileName = ThemeConstants.PowerCommandApplication;
73 p.StartInfo.Arguments = "/shutdown";
74 #if !TEST_NEXUS_POWER_COMMAND
75 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
76 #endif
77 p.Start();
78 #if !DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND
79 this.Close();
80 #endif
81 }
82
83 private void btnRestart_Click(object sender, EventArgs e)
84 {
85 // restart the computer
86 Process p = new Process();
87 p.StartInfo.FileName = ThemeConstants.PowerCommandApplication;
88 p.StartInfo.Arguments = "/restart";
89 #if !TEST_NEXUS_POWER_COMMAND
90 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
91 #endif
92 p.Start();
93 #if !DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND
94 this.Close();
95 #endif
96 }
97
98 private void btnLogoff_Click(object sender, EventArgs e)
99 {
100 // logoff the current user
101 Process p = new Process();
102 p.StartInfo.FileName = ThemeConstants.PowerCommandApplication;
103 p.StartInfo.Arguments = "/logoff";
104 #if !TEST_NEXUS_POWER_COMMAND
105 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
106 #endif
107 p.Start();
108 #if !DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND
109 this.Close();
110 #endif
111 }
112
113 private void btnLockScreen_Click(object sender, EventArgs e)
114 {
115 // lock the screen
116 Process p = new Process();
117 p.StartInfo.FileName = ThemeConstants.PowerCommandApplication;
118 p.StartInfo.Arguments = "/lock";
119 #if !TEST_NEXUS_POWER_COMMAND
120 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
121 #endif
122 p.Start();
123 #if !DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND
124 this.Close();
125 #endif
126 }
127
128 private void btnSleep_Click(object sender, EventArgs e)
129 {
130 // put the computer to sleep
131 Process p = new Process();
132 p.StartInfo.FileName = ThemeConstants.PowerCommandApplication;
133 p.StartInfo.Arguments = "/sleep";
134 #if !TEST_NEXUS_POWER_COMMAND
135 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
136 #endif
137 p.Start();
138 #if !DONOT_CLOSE_MAIN_FORM_WHEN_TESTING_NEXUS_POWER_COMMAND
139 this.Close();
140 #endif
141 }
142
143 private void btnClose_Click(object sender, EventArgs e)
144 {
145 // close this dialog
146 this.Close();
147 }
148 }
149 }

  ViewVC Help
Powered by ViewVC 1.1.22