protected override void OnDrawItem(DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); if (e.Index >= 0) { ProcData data = Items[e.Index] as ProcData; if (data != null) { e.Graphics.DrawString(data.procName, e.Font, new SolidBrush(ForeColor), e.Bounds.Left, e.Bounds.Top); } } base.OnDrawItem(e); }
void RefreshProcList() { procList.Items.Clear(); Process[] processes = Process.GetProcesses(); foreach (Process proc in processes) { if (string.IsNullOrEmpty(proc.MainWindowTitle)) { continue; } ProcData procData = new ProcData(); procData.procId = proc.Id; procData.procName = proc.MainWindowTitle; procList.Items.Add(procData); } }
void AutoKeyThread() { while (running) { procList.Invoke(new MethodInvoker(() => { if (procList.SelectedItem == null) { return; } ProcData data = (ProcData)procList.SelectedItem; bool exists = Process.GetProcesses().Any(x => x.Id == data.procId); if (exists) { Process proc = Process.GetProcessById(data.procId); if (proc != null) { if (GetForegroundWindow() == proc.MainWindowHandle) { SendKeys.Send("^s"); } } } else { MessageBox.Show("프로세스가 종료되어있어 자동 저장을 종료합니다."); running = false; button1.Text = "Run"; } })); if (!running) { break; } Thread.Sleep(delay); } }