@@ -17,9 +17,9 @@ namespace TimeControl
1717 public partial class ControlPanel : Form
1818 {
1919 private bool hide = false ; //指示启动后是否需要隐藏
20- private bool closable = false ; //指示当前是否可以关闭
20+ private bool isClosable = false ; //指示当前是否可以关闭
2121 List < App > appList = new ( ) ; //所有监控软件列表
22- private int unlockPasswordHash = 0 ; //密码哈希值,用作比对
22+ private int unlockPasswordHash = 0 ; //密码哈希值,用作比对
2323 public ControlPanel ( bool hide )
2424 {
2525 InitializeComponent ( ) ;
@@ -52,18 +52,18 @@ private void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)//打
5252
5353 private void ControlPanel_FormClosing ( object sender , FormClosingEventArgs e ) //处理关闭逻辑
5454 {
55- if ( ! closable ) //隐藏窗口
55+ if ( ! isClosable ) //隐藏窗口
5656 {
5757 e . Cancel = true ;
5858 Hide ( ) ;
5959 }
6060 else //退出前关闭保护进程
6161 {
62- Process [ ] processes = Process . GetProcessesByName ( "TimeControlConsole" ) ;
63- foreach ( Process process in processes )
64- {
65- process . Kill ( ) ;
66- }
62+ Process [ ] processes = Process . GetProcessesByName ( "TimeControlConsole" ) ;
63+ foreach ( Process process in processes )
64+ {
65+ process . Kill ( ) ;
66+ }
6767 }
6868 }
6969
@@ -87,28 +87,25 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
8787 private void AppAddButton_Click ( object sender , EventArgs e ) //添加打开的窗口
8888 {
8989 processMonitorTimer . Stop ( ) ;
90- appList . Clear ( ) ;
91- Process [ ] processes = Process . GetProcesses ( ) ;
92- foreach ( Process process in processes )
90+ Process [ ] processes = Process . GetProcessesByName ( processNameBox . Text ) ;
91+ try
9392 {
94- if ( ! string . IsNullOrEmpty ( process . MainWindowTitle ) )
93+ foreach ( Process process in processes )
9594 {
96- try
97- {
98- appList . Add ( new App ( process . ProcessName , process . MainModule . FileName ) ) ;
99- }
100- catch ( Exception ex )
101- {
102- MessageBox . Show ( ex . Message , "错误" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ; //防止无法访问错误
103- }
95+ appList . Add ( new App ( process . ProcessName , process . MainModule . FileName ) ) ;
10496 }
10597 }
98+ catch ( Exception ex )
99+ {
100+ MessageBox . Show ( "错误" , ex . Message , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
101+ }
106102 CalculateTime ( ) ;
107103 }
108104
109105 private void RemoveButton_Click ( object sender , EventArgs e ) //移除所有的已添加窗口
110106 {
111- appList . Clear ( ) ;
107+ if ( usageBox . SelectedIndex >= 0 )
108+ appList . RemoveAt ( usageBox . SelectedIndex ) ;
112109 CalculateTime ( ) ;
113110 }
114111
@@ -137,9 +134,9 @@ private void CalculateTime()//将进程时间推送到ListBox控件
137134 ListBoxController . Refresh ( usageBox , appList ) ;
138135 processMonitorTimer . Start ( ) ;
139136 }
140- private void ForceClose ( )
137+ private void ForceClose ( ) //可以正常关闭
141138 {
142- closable = true ;
139+ isClosable = true ;
143140 Close ( ) ;
144141 }
145142 private void ControlPanel_Shown ( object sender , EventArgs e ) //启动隐藏参数支持
@@ -153,7 +150,7 @@ private void ControlPanel_Shown(object sender, EventArgs e)//启动隐藏参数
153150 }
154151 private void unloackPassWordSetButton_Click ( object sender , EventArgs e ) //保存密码
155152 {
156- unlockPasswordHash = unlockPasswordBox . Text . GetHashCode ( ) ; //保存哈希值
153+ unlockPasswordHash = unlockPasswordBox . Text . GetHashCode ( ) ; //保存哈希值
157154 unlockPasswordBox . Text = "" ;
158155 unlockPasswordBox . Enabled = false ;
159156 unloackPassWordSetButton . Enabled = false ;
0 commit comments