|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleControlSample
{
public partial class FormConsoleControlSample : Form
{
public FormConsoleControlSample()
{
InitializeComponent();
}
private void FormConsoleControlSample_Load(object sender, EventArgs e)
{
// Update the UI state.
UpdateUIState();
}
/// <summary>
/// Handles the Click event of the toolStripButtonNewProcess control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void toolStripButtonNewProcess_Click(object sender, EventArgs e)
{
// Create the new process form.
FormNewProcess formNewProcess = new FormNewProcess();
// If the form is shown OK, start the process.
if (formNewProcess.ShowDialog() == DialogResult.OK)
{
// Start the proces.
consoleControl.StartProcess(formNewProcess.FileName, formNewProcess.Arguments);
// Update the UI state.
UpdateUIState();
}
}
/// <summary>
/// Handles the Click event of the toolStripButtonStopProcess control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void toolStripButtonStopProcess_Click(object sender, EventArgs e)
{
consoleControl.StopProcess();
// Update the UI state.
UpdateUIState();
}
private void UpdateUIState()
{
// Update the state.
if (consoleControl.IsProcessRunning)
toolStripStatusLabelConsoleState.Text = "Running " + System.IO.Path.GetFileName(consoleControl.CurrentProcess.MainModule.FileName);
else
toolStripStatusLabelConsoleState.Text = "Not Running";
// Update toolbar buttons.
toolStripButtonRunCMD.Enabled = !consoleControl.IsProcessRunning;
toolStripButtonNewProcess.Enabled = !consoleControl.IsProcessRunning;
toolStripButtonStopProcess.Enabled = consoleControl.IsProcessRunning;
toolStripButtonShowDiagnostics.Checked = consoleControl.ShowDiagnostics;
toolStripButtonInputEnabled.Checked = consoleControl.IsInputEnabled;
}
private void toolStripButtonShowDiagnostics_Click(object sender, EventArgs e)
{
consoleControl.ShowDiagnostics = !consoleControl.ShowDiagnostics;
UpdateUIState();
}
private void timerUpdateUI_Tick(object sender, EventArgs e)
{
UpdateUIState();
}
private void toolStripButtonInputEnabled_Click(object sender, EventArgs e)
{
consoleControl.IsInputEnabled = !consoleControl.IsInputEnabled;
UpdateUIState();
}
private void toolStripButtonRunCMD_Click(object sender, EventArgs e)
{
consoleControl.StartProcess("cmd", null);
UpdateUIState();
}
private void toolStripButtonClearOutput_Click(object sender, EventArgs e)
{
consoleControl.ClearOutput();
}
}
}
|
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.