|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
namespace Automator
{
/// <summary>
/// Summary description for ProcessBrowserForm.
/// </summary>
public class ProcessBrowserForm : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox processList;
private System.Windows.Forms.Panel buttonsPanel;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button reloadButton;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public string ProcessTitle
{
get
{
return this.processList.SelectedItem.ToString();
}
}
public ProcessBrowserForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.reloadButton_Click(null, null);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.processList = new System.Windows.Forms.ListBox();
this.buttonsPanel = new System.Windows.Forms.Panel();
this.reloadButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.buttonsPanel.SuspendLayout();
this.SuspendLayout();
//
// processList
//
this.processList.Dock = System.Windows.Forms.DockStyle.Fill;
this.processList.Location = new System.Drawing.Point(0, 0);
this.processList.Name = "processList";
this.processList.ScrollAlwaysVisible = true;
this.processList.Size = new System.Drawing.Size(292, 264);
this.processList.Sorted = true;
this.processList.TabIndex = 1;
this.processList.SelectedIndexChanged += new System.EventHandler(this.processList_SelectedIndexChanged);
//
// buttonsPanel
//
this.buttonsPanel.Controls.Add(this.reloadButton);
this.buttonsPanel.Controls.Add(this.okButton);
this.buttonsPanel.Controls.Add(this.cancelButton);
this.buttonsPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.buttonsPanel.Location = new System.Drawing.Point(0, 226);
this.buttonsPanel.Name = "buttonsPanel";
this.buttonsPanel.Size = new System.Drawing.Size(292, 40);
this.buttonsPanel.TabIndex = 2;
//
// reloadButton
//
this.reloadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.reloadButton.Location = new System.Drawing.Point(8, 8);
this.reloadButton.Name = "reloadButton";
this.reloadButton.Size = new System.Drawing.Size(72, 24);
this.reloadButton.TabIndex = 3;
this.reloadButton.Text = "Reload";
this.reloadButton.Click += new System.EventHandler(this.reloadButton_Click);
//
// okButton
//
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.okButton.Enabled = false;
this.okButton.Location = new System.Drawing.Point(232, 8);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(56, 24);
this.okButton.TabIndex = 2;
this.okButton.Text = "OK";
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(160, 8);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(56, 24);
this.cancelButton.TabIndex = 1;
this.cancelButton.Text = "Cancel";
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// ProcessBrowserForm
//
this.AcceptButton = this.okButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.buttonsPanel);
this.Controls.Add(this.processList);
this.Name = "ProcessBrowserForm";
this.Text = "Process Browser";
this.buttonsPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void reloadButton_Click(object sender, System.EventArgs e)
{
this.reloadButton.Enabled = false;
this.processList.Items.Clear();
Process[] plist = Process.GetProcesses();
foreach (Process p in plist)
{
if (p.MainWindowTitle.Trim().Length > 0)
{
this.processList.Items.Add(p.MainWindowTitle.Trim());
}
}
this.reloadButton.Enabled = true;
}
private void okButton_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
private void cancelButton_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void processList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.processList.SelectedIndices.Count == 1)
{
this.okButton.Enabled = true;
}
else
{
this.okButton.Enabled = false;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.