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

Annotation of /trunk/NexusPowerControl/MainUI.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations) (download)
Tue Oct 25 07:48:20 2011 UTC (8 years, 1 month 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 william 25 //#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 william 24 using System;
4 william 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 william 24 using System.Diagnostics;
12 william 4
13     namespace NexusPowerControl
14     {
15 william 13 public partial class MainUI : Form
16 william 4 {
17 william 15 MouseTrapper mouse_trapper = new MouseTrapper();
18 william 13 public MainUI()
19 william 4 {
20     InitializeComponent();
21     }
22 william 8
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 william 10
30     if (theme.ThemeLoaded)
31     {
32     pic_main.Image = Image.FromFile(theme.MainImage);
33 william 16 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 william 10 }
40 william 21 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 william 10
51 william 11
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 william 8 }
59 william 15 private void MainUI_Shown(object sender, EventArgs e)
60     {
61     mouse_trapper.TrapMouse(this);
62     }
63 william 10
64 william 15 private void MainUI_FormClosed(object sender, FormClosedEventArgs e)
65     {
66     mouse_trapper.ReleaseMouse(this);
67     }
68 william 10 private void btnShutdown_Click(object sender, EventArgs e)
69     {
70 william 12 // shutdown the computer
71 william 24 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 william 10 }
82    
83     private void btnRestart_Click(object sender, EventArgs e)
84     {
85 william 12 // restart the computer
86 william 24 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 william 10 }
97    
98     private void btnLogoff_Click(object sender, EventArgs e)
99     {
100 william 12 // logoff the current user
101 william 24 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 william 10 }
112    
113     private void btnLockScreen_Click(object sender, EventArgs e)
114     {
115 william 12 // lock the screen
116 william 24 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 william 10 }
127    
128     private void btnSleep_Click(object sender, EventArgs e)
129     {
130 william 12 // put the computer to sleep
131 william 24 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 william 10 }
142    
143     private void btnClose_Click(object sender, EventArgs e)
144     {
145 william 12 // close this dialog
146 william 11 this.Close();
147     }
148 william 4 }
149     }

  ViewVC Help
Powered by ViewVC 1.1.22