using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms; // for Application


namespace MyNamespace
{
	/// <summary>
	///		Run form for input and output to control calculations
	///		Developed in TURBO Pascal 5.5 and 6.0, converted to Visual Basic 6
	///		and now in Visual C# .Net
	///
	/// ---------------- *** LEGAL NOTICE: *** ------------------
	///
	/// This program is free software; you can redistribute it and/or modify
	/// it under the terms of the GNU General Public License (GPL) as published
	/// by the Free Software Foundation. cf. the file COPYING.txt.
	///
	/// ------------ *** end of legal notice *** ------------------
	/// </summary>

	public class RunForm : Form
	{
		private Button buttonAbortCalc;
		private Button buttonCalculate;
		private Button buttonClearInput;
		private Button buttonClearLogFile;
		private Button buttonClearOutput;
		private Button buttonConfiguration;
		private Button buttonLog;
		private Button buttonPause;
		private Button buttonQuit;
		private Button buttonRestoreAll;
		private Button buttonRestoreInput;
		private Button buttonSaveAll;
		private Button buttonStatusOfCalc;
		private Label labelCtrlF9;
		private Label labelCtrlS;
		private Label labelCtrlZ;
		private Label labelEsc;
		private Label labelF11;
		private Label labelF12;
		private Label labelF2;
		private Label labelF5;
		private Label labelF6;
		private Label labelF7;
		private Label labelF8;
		private Label labelF9;
		private Label labelOvertype;
		private Label labelRunning;
		private MainMenu mainMenuRun;
		private MenuItem cbOnTop;
		private MenuItem menuItemAbout;
		private MenuItem menuItemExit;
		private MenuItem menuItemFile;
		private MenuItem menuItemHelp;
		private MenuItem menuItemHelpForm;
		private MenuItem menuItemPause;
		private MenuItem menuItemRestart;
		private MenuItem menuItemRestore;
		private MenuItem menuItemRestoreF3;
		private MenuItem menuItemRestoreF4;
		private RichTextBox richTextIn;
		private RichTextBox richTextOut;
		private System.ComponentModel.IContainer components;
		private Label labelCtrlF11;
		private Timer timerRun;

		public RunForm()
		{
			InitializeComponent();

			Global.runTextOut = richTextOut;
			Global.runTextOut.Clear();
			Global.runTextIn = richTextIn;
			Global.runTextIn.Clear();
			Global.objRunForm = this;
			this.Width = runWidth;			// Resize the form
			this.Height = runHeight;
			this.CenterToScreen();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			runWidth = this.Width;
			runHeight = this.Height;
			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.components = new System.ComponentModel.Container();
			System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RunForm));
			this.richTextIn = new System.Windows.Forms.RichTextBox();
			this.richTextOut = new System.Windows.Forms.RichTextBox();
			this.mainMenuRun = new System.Windows.Forms.MainMenu(this.components);
			this.menuItemFile = new System.Windows.Forms.MenuItem();
			this.menuItemPause = new System.Windows.Forms.MenuItem();
			this.menuItemRestart = new System.Windows.Forms.MenuItem();
			this.menuItemExit = new System.Windows.Forms.MenuItem();
			this.menuItemRestore = new System.Windows.Forms.MenuItem();
			this.menuItemRestoreF3 = new System.Windows.Forms.MenuItem();
			this.menuItemRestoreF4 = new System.Windows.Forms.MenuItem();
			this.menuItemHelp = new System.Windows.Forms.MenuItem();
			this.menuItemHelpForm = new System.Windows.Forms.MenuItem();
			this.cbOnTop = new System.Windows.Forms.MenuItem();
			this.menuItemAbout = new System.Windows.Forms.MenuItem();
			this.buttonClearLogFile = new System.Windows.Forms.Button();
			this.buttonLog = new System.Windows.Forms.Button();
			this.buttonClearInput = new System.Windows.Forms.Button();
			this.buttonClearOutput = new System.Windows.Forms.Button();
			this.buttonSaveAll = new System.Windows.Forms.Button();
			this.buttonPause = new System.Windows.Forms.Button();
			this.buttonAbortCalc = new System.Windows.Forms.Button();
			this.buttonStatusOfCalc = new System.Windows.Forms.Button();
			this.buttonConfiguration = new System.Windows.Forms.Button();
			this.buttonRestoreInput = new System.Windows.Forms.Button();
			this.buttonCalculate = new System.Windows.Forms.Button();
			this.buttonRestoreAll = new System.Windows.Forms.Button();
			this.buttonQuit = new System.Windows.Forms.Button();
			this.timerRun = new System.Windows.Forms.Timer(this.components);
			this.labelRunning = new System.Windows.Forms.Label();
			this.labelF5 = new System.Windows.Forms.Label();
			this.labelF9 = new System.Windows.Forms.Label();
			this.labelF12 = new System.Windows.Forms.Label();
			this.labelEsc = new System.Windows.Forms.Label();
			this.labelF6 = new System.Windows.Forms.Label();
			this.labelF7 = new System.Windows.Forms.Label();
			this.labelF8 = new System.Windows.Forms.Label();
			this.labelF2 = new System.Windows.Forms.Label();
			this.labelF11 = new System.Windows.Forms.Label();
			this.labelCtrlF9 = new System.Windows.Forms.Label();
			this.labelCtrlS = new System.Windows.Forms.Label();
			this.labelCtrlZ = new System.Windows.Forms.Label();
			this.labelOvertype = new System.Windows.Forms.Label();
			this.labelCtrlF11 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// richTextIn
			// 
			this.richTextIn.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.richTextIn.Location = new System.Drawing.Point(0, 88);
			this.richTextIn.Name = "richTextIn";
			this.richTextIn.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical;
			this.richTextIn.Size = new System.Drawing.Size(664, 104);
			this.richTextIn.TabIndex = 0;
			this.richTextIn.Text = "";
			this.richTextIn.KeyDown += new System.Windows.Forms.KeyEventHandler(this.richTextIn_KeyDown);
			this.richTextIn.KeyUp += new System.Windows.Forms.KeyEventHandler(this.richTextIn_KeyUp);
			this.richTextIn.TextChanged += new System.EventHandler(this.richTextIn_TextChanged);
			// 
			// richTextOut
			// 
			this.richTextOut.BackColor = System.Drawing.SystemColors.Window;
			this.richTextOut.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.richTextOut.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.richTextOut.Location = new System.Drawing.Point(0, 192);
			this.richTextOut.Name = "richTextOut";
			this.richTextOut.ReadOnly = true;
			this.richTextOut.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical;
			this.richTextOut.Size = new System.Drawing.Size(664, 344);
			this.richTextOut.TabIndex = 14;
			this.richTextOut.Text = "";
			this.richTextOut.KeyDown += new System.Windows.Forms.KeyEventHandler(this.richTextOut_KeyDown);
			// 
			// mainMenuRun
			// 
			this.mainMenuRun.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItemFile,
            this.menuItemRestore,
            this.menuItemHelp});
			// 
			// menuItemFile
			// 
			this.menuItemFile.Index = 0;
			this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItemPause,
            this.menuItemRestart,
            this.menuItemExit});
			this.menuItemFile.Text = " &File ";
			// 
			// menuItemPause
			// 
			this.menuItemPause.Index = 0;
			this.menuItemPause.Text = "&Pause        F12";
			this.menuItemPause.Click += new System.EventHandler(this.menuItemPause_Click);
			// 
			// menuItemRestart
			// 
			this.menuItemRestart.Index = 1;
			this.menuItemRestart.Text = "&Restart      Ctrl+F2";
			this.menuItemRestart.Click += new System.EventHandler(this.menuItemRestart_Click);
			// 
			// menuItemExit
			// 
			this.menuItemExit.Index = 2;
			this.menuItemExit.Text = "E&xit";
			this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
			// 
			// menuItemRestore
			// 
			this.menuItemRestore.Index = 1;
			this.menuItemRestore.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItemRestoreF3,
            this.menuItemRestoreF4});
			this.menuItemRestore.Text = "Restore";
			// 
			// menuItemRestoreF3
			// 
			this.menuItemRestoreF3.Index = 0;
			this.menuItemRestoreF3.Text = "Restore previous input command    F3";
			this.menuItemRestoreF3.Click += new System.EventHandler(this.menuItemRestoreF3_Click);
			// 
			// menuItemRestoreF4
			// 
			this.menuItemRestoreF4.Index = 1;
			this.menuItemRestoreF4.Text = "Accept previous input command      F4";
			this.menuItemRestoreF4.Click += new System.EventHandler(this.menuItemRestoreF4_Click);
			// 
			// menuItemHelp
			// 
			this.menuItemHelp.Index = 2;
			this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItemHelpForm,
            this.cbOnTop,
            this.menuItemAbout});
			this.menuItemHelp.Text = " &Help F1 ";
			// 
			// menuItemHelpForm
			// 
			this.menuItemHelpForm.Index = 0;
			this.menuItemHelpForm.Text = "&Help Form        F1";
			this.menuItemHelpForm.Click += new System.EventHandler(this.menuItemHelpForm_Click);
			// 
			// cbOnTop
			// 
			this.cbOnTop.Checked = ((bool)(configurationAppSettings.GetValue("cbOnTop.Checked", typeof(bool))));
			this.cbOnTop.Index = 1;
			this.cbOnTop.Text = "On Top";
			this.cbOnTop.Click += new System.EventHandler(this.cbOnTop_Click);
			// 
			// menuItemAbout
			// 
			this.menuItemAbout.Index = 2;
			this.menuItemAbout.Text = "&About...";
			this.menuItemAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
			// 
			// buttonClearLogFile
			// 
			this.buttonClearLogFile.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.buttonClearLogFile.Location = new System.Drawing.Point(16, 8);
			this.buttonClearLogFile.Name = "buttonClearLogFile";
			this.buttonClearLogFile.Size = new System.Drawing.Size(88, 23);
			this.buttonClearLogFile.TabIndex = 4;
			this.buttonClearLogFile.Text = "Clear Log File";
			this.buttonClearLogFile.Click += new System.EventHandler(this.buttonClearLogFile_Click);
			// 
			// buttonLog
			// 
			this.buttonLog.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.buttonLog.Font = new System.Drawing.Font("Tahoma", 7.75F, System.Drawing.FontStyle.Bold);
			this.buttonLog.Location = new System.Drawing.Point(112, 8);
			this.buttonLog.Name = "buttonLog";
			this.buttonLog.Size = new System.Drawing.Size(88, 23);
			this.buttonLog.TabIndex = 5;
			this.buttonLog.Text = "Logging Is Off";
			this.buttonLog.Click += new System.EventHandler(this.buttonLog_Click);
			// 
			// buttonClearInput
			// 
			this.buttonClearInput.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonClearInput.Location = new System.Drawing.Point(304, 8);
			this.buttonClearInput.Name = "buttonClearInput";
			this.buttonClearInput.Size = new System.Drawing.Size(88, 23);
			this.buttonClearInput.TabIndex = 6;
			this.buttonClearInput.Text = "Clear Input";
			this.buttonClearInput.Click += new System.EventHandler(this.buttonClearInput_Click);
			// 
			// buttonClearOutput
			// 
			this.buttonClearOutput.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonClearOutput.Location = new System.Drawing.Point(400, 8);
			this.buttonClearOutput.Name = "buttonClearOutput";
			this.buttonClearOutput.Size = new System.Drawing.Size(88, 23);
			this.buttonClearOutput.TabIndex = 7;
			this.buttonClearOutput.Text = "Clear Output";
			this.buttonClearOutput.Click += new System.EventHandler(this.buttonClearOutput_Click);
			// 
			// buttonSaveAll
			// 
			this.buttonSaveAll.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonSaveAll.Location = new System.Drawing.Point(496, 8);
			this.buttonSaveAll.Name = "buttonSaveAll";
			this.buttonSaveAll.Size = new System.Drawing.Size(88, 23);
			this.buttonSaveAll.TabIndex = 8;
			this.buttonSaveAll.Text = "Save All";
			this.buttonSaveAll.Click += new System.EventHandler(this.buttonSaveAll_Click);
			// 
			// buttonPause
			// 
			this.buttonPause.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonPause.Location = new System.Drawing.Point(592, 8);
			this.buttonPause.Name = "buttonPause";
			this.buttonPause.Size = new System.Drawing.Size(48, 23);
			this.buttonPause.TabIndex = 9;
			this.buttonPause.Text = "Pause";
			this.buttonPause.Click += new System.EventHandler(this.buttonPause_Click);
			// 
			// buttonAbortCalc
			// 
			this.buttonAbortCalc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonAbortCalc.Location = new System.Drawing.Point(16, 48);
			this.buttonAbortCalc.Name = "buttonAbortCalc";
			this.buttonAbortCalc.Size = new System.Drawing.Size(88, 23);
			this.buttonAbortCalc.TabIndex = 10;
			this.buttonAbortCalc.Text = "Abort Calc.";
			this.buttonAbortCalc.Click += new System.EventHandler(this.buttonAbortCalc_Click);
			// 
			// buttonStatusOfCalc
			// 
			this.buttonStatusOfCalc.Font = new System.Drawing.Font("Tahoma", 7.5F, System.Drawing.FontStyle.Bold);
			this.buttonStatusOfCalc.Location = new System.Drawing.Point(112, 48);
			this.buttonStatusOfCalc.Name = "buttonStatusOfCalc";
			this.buttonStatusOfCalc.Size = new System.Drawing.Size(88, 23);
			this.buttonStatusOfCalc.TabIndex = 11;
			this.buttonStatusOfCalc.Text = "Status of Calc.";
			this.buttonStatusOfCalc.Click += new System.EventHandler(this.buttonStatusOfCalc_Click);
			// 
			// buttonConfiguration
			// 
			this.buttonConfiguration.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.buttonConfiguration.Location = new System.Drawing.Point(208, 48);
			this.buttonConfiguration.Name = "buttonConfiguration";
			this.buttonConfiguration.Size = new System.Drawing.Size(88, 23);
			this.buttonConfiguration.TabIndex = 12;
			this.buttonConfiguration.Text = "Configuration";
			this.buttonConfiguration.Click += new System.EventHandler(this.buttonConfiguration_Click);
			// 
			// buttonRestoreInput
			// 
			this.buttonRestoreInput.Font = new System.Drawing.Font("Tahoma", 7.75F, System.Drawing.FontStyle.Bold);
			this.buttonRestoreInput.Location = new System.Drawing.Point(304, 48);
			this.buttonRestoreInput.Name = "buttonRestoreInput";
			this.buttonRestoreInput.Size = new System.Drawing.Size(88, 23);
			this.buttonRestoreInput.TabIndex = 13;
			this.buttonRestoreInput.Text = "Restore Input";
			this.buttonRestoreInput.Click += new System.EventHandler(this.buttonRestoreInput_Click);
			// 
			// buttonCalculate
			// 
			this.buttonCalculate.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonCalculate.Location = new System.Drawing.Point(400, 48);
			this.buttonCalculate.Name = "buttonCalculate";
			this.buttonCalculate.Size = new System.Drawing.Size(88, 23);
			this.buttonCalculate.TabIndex = 1;
			this.buttonCalculate.Text = "Calculate";
			this.buttonCalculate.Click += new System.EventHandler(this.buttonCalculate_Click);
			// 
			// buttonRestoreAll
			// 
			this.buttonRestoreAll.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonRestoreAll.Location = new System.Drawing.Point(496, 48);
			this.buttonRestoreAll.Name = "buttonRestoreAll";
			this.buttonRestoreAll.Size = new System.Drawing.Size(88, 23);
			this.buttonRestoreAll.TabIndex = 2;
			this.buttonRestoreAll.Text = "Restore All";
			this.buttonRestoreAll.Click += new System.EventHandler(this.buttonRestoreAll_Click);
			// 
			// buttonQuit
			// 
			this.buttonQuit.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.buttonQuit.Location = new System.Drawing.Point(592, 48);
			this.buttonQuit.Name = "buttonQuit";
			this.buttonQuit.Size = new System.Drawing.Size(48, 23);
			this.buttonQuit.TabIndex = 3;
			this.buttonQuit.Text = "Quit";
			this.buttonQuit.Click += new System.EventHandler(this.buttonQuit_Click);
			// 
			// timerRun
			// 
			this.timerRun.Enabled = true;
			this.timerRun.Interval = 1000;
			this.timerRun.Tick += new System.EventHandler(this.timerRun_Tick);
			// 
			// labelRunning
			// 
			this.labelRunning.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelRunning.Location = new System.Drawing.Point(208, 8);
			this.labelRunning.Name = "labelRunning";
			this.labelRunning.Size = new System.Drawing.Size(96, 16);
			this.labelRunning.TabIndex = 15;
			this.labelRunning.Text = "**Running**";
			// 
			// labelF5
			// 
			this.labelF5.Font = new System.Drawing.Font("Tahoma", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF5.Location = new System.Drawing.Point(144, 72);
			this.labelF5.Name = "labelF5";
			this.labelF5.Size = new System.Drawing.Size(16, 16);
			this.labelF5.TabIndex = 16;
			this.labelF5.Text = "F5";
			// 
			// labelF9
			// 
			this.labelF9.Font = new System.Drawing.Font("Tahoma", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF9.Location = new System.Drawing.Point(144, 32);
			this.labelF9.Name = "labelF9";
			this.labelF9.Size = new System.Drawing.Size(24, 16);
			this.labelF9.TabIndex = 17;
			this.labelF9.Text = "F9";
			// 
			// labelF12
			// 
			this.labelF12.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF12.Location = new System.Drawing.Point(608, 32);
			this.labelF12.Name = "labelF12";
			this.labelF12.Size = new System.Drawing.Size(24, 16);
			this.labelF12.TabIndex = 18;
			this.labelF12.Text = "F12";
			// 
			// labelEsc
			// 
			this.labelEsc.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelEsc.Location = new System.Drawing.Point(48, 72);
			this.labelEsc.Name = "labelEsc";
			this.labelEsc.Size = new System.Drawing.Size(24, 16);
			this.labelEsc.TabIndex = 19;
			this.labelEsc.Text = "Esc";
			// 
			// labelF6
			// 
			this.labelF6.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF6.Location = new System.Drawing.Point(240, 72);
			this.labelF6.Name = "labelF6";
			this.labelF6.Size = new System.Drawing.Size(24, 16);
			this.labelF6.TabIndex = 20;
			this.labelF6.Text = "F6";
			// 
			// labelF7
			// 
			this.labelF7.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF7.Location = new System.Drawing.Point(336, 72);
			this.labelF7.Name = "labelF7";
			this.labelF7.Size = new System.Drawing.Size(24, 16);
			this.labelF7.TabIndex = 21;
			this.labelF7.Text = "F7";
			// 
			// labelF8
			// 
			this.labelF8.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF8.Location = new System.Drawing.Point(432, 72);
			this.labelF8.Name = "labelF8";
			this.labelF8.Size = new System.Drawing.Size(24, 16);
			this.labelF8.TabIndex = 22;
			this.labelF8.Text = "F8";
			// 
			// labelF2
			// 
			this.labelF2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF2.Location = new System.Drawing.Point(608, 72);
			this.labelF2.Name = "labelF2";
			this.labelF2.Size = new System.Drawing.Size(24, 16);
			this.labelF2.TabIndex = 23;
			this.labelF2.Text = "F2";
			// 
			// labelF11
			// 
			this.labelF11.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelF11.Location = new System.Drawing.Point(432, 32);
			this.labelF11.Name = "labelF11";
			this.labelF11.Size = new System.Drawing.Size(33, 16);
			this.labelF11.TabIndex = 25;
			this.labelF11.Text = "F11";
			// 
			// labelCtrlF9
			// 
			this.labelCtrlF9.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelCtrlF9.Location = new System.Drawing.Point(40, 32);
			this.labelCtrlF9.Name = "labelCtrlF9";
			this.labelCtrlF9.Size = new System.Drawing.Size(40, 16);
			this.labelCtrlF9.TabIndex = 26;
			this.labelCtrlF9.Text = "Ctrl+F9";
			// 
			// labelCtrlS
			// 
			this.labelCtrlS.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelCtrlS.Location = new System.Drawing.Point(520, 32);
			this.labelCtrlS.Name = "labelCtrlS";
			this.labelCtrlS.Size = new System.Drawing.Size(40, 16);
			this.labelCtrlS.TabIndex = 27;
			this.labelCtrlS.Text = "Ctrl+S";
			// 
			// labelCtrlZ
			// 
			this.labelCtrlZ.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelCtrlZ.Location = new System.Drawing.Point(520, 72);
			this.labelCtrlZ.Name = "labelCtrlZ";
			this.labelCtrlZ.Size = new System.Drawing.Size(32, 16);
			this.labelCtrlZ.TabIndex = 28;
			this.labelCtrlZ.Text = "Ctrl+O";
			// 
			// labelOvertype
			// 
			this.labelOvertype.Location = new System.Drawing.Point(216, 32);
			this.labelOvertype.Name = "labelOvertype";
			this.labelOvertype.Size = new System.Drawing.Size(72, 16);
			this.labelOvertype.TabIndex = 29;
			this.labelOvertype.Text = "Overtype Off";
			// 
			// labelCtrlF11
			// 
			this.labelCtrlF11.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.labelCtrlF11.Location = new System.Drawing.Point(323, 31);
			this.labelCtrlF11.Name = "labelCtrlF11";
			this.labelCtrlF11.Size = new System.Drawing.Size(49, 16);
			this.labelCtrlF11.TabIndex = 30;
			this.labelCtrlF11.Text = "Ctrl+F11";
			// 
			// RunForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(666, 509);
			this.Controls.Add(this.labelCtrlF11);
			this.Controls.Add(this.labelOvertype);
			this.Controls.Add(this.labelCtrlZ);
			this.Controls.Add(this.labelCtrlS);
			this.Controls.Add(this.labelCtrlF9);
			this.Controls.Add(this.labelF11);
			this.Controls.Add(this.labelF2);
			this.Controls.Add(this.labelF8);
			this.Controls.Add(this.labelF7);
			this.Controls.Add(this.labelF6);
			this.Controls.Add(this.labelEsc);
			this.Controls.Add(this.labelF12);
			this.Controls.Add(this.labelF9);
			this.Controls.Add(this.labelF5);
			this.Controls.Add(this.labelRunning);
			this.Controls.Add(this.buttonQuit);
			this.Controls.Add(this.buttonRestoreAll);
			this.Controls.Add(this.buttonCalculate);
			this.Controls.Add(this.buttonRestoreInput);
			this.Controls.Add(this.buttonConfiguration);
			this.Controls.Add(this.buttonStatusOfCalc);
			this.Controls.Add(this.buttonAbortCalc);
			this.Controls.Add(this.buttonPause);
			this.Controls.Add(this.buttonSaveAll);
			this.Controls.Add(this.buttonClearOutput);
			this.Controls.Add(this.buttonClearInput);
			this.Controls.Add(this.buttonLog);
			this.Controls.Add(this.buttonClearLogFile);
			this.Controls.Add(this.richTextOut);
			this.Controls.Add(this.richTextIn);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenuRun;
			this.Name = "RunForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "<App.Title> - Run";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.memberFormClosing);
			this.Resize += new System.EventHandler(this.RunForm_Resize);
			this.ResumeLayout(false);

		}
		#endregion

		public void Run(int iMaxDigits, int iMComs, StartupForm callerForm)
		// -------- Begin Main program Run for input and output to control calculations
		{
			if (Global.runFormUp) { Dispose(true); return; }
			Common.tExitFlag = false;
			tQuitFlag = true;
			Global.runFormUp = true;
			Global.programURL = "http://www.geocities.com/hjsmithh/Calc/";
			this.Show();
			this.Text = Global.title + " - Run";
			objStartupForm = callerForm;
			labelRunning.Text = "**Running**";
			if (Common.homeDir == null) Common.homeDir = Environment.CurrentDirectory.ToString();
			if (Common.selectPath == null) Common.selectPath = Common.homeDir;
			if (Common.selectFile == null) Common.selectFile = "";
			if (Common.selectFilter == 0) Common.selectFilter = 1;
			Common.cComs = 0;					// initialize command history list
			Common.mComs = iMComs;
			Common.comHL = new string[Common.mComs+1];
			Common.comPF = new string[Common.mComs+1];
			Common.logFile = "";
			Common.histFile = Global.pName + "Hist.txt";
			Common.histBak = Global.pName + "Hist.Bak";
			MultiID.abortCalc = false;
			MultiID.logg = false;				// log file not open
			MultiID.outS = Global.runTextOut;
			Common.inS = Global.runTextIn;
			Common.runCmdLog = buttonLog;
			Global.runTextOut.Clear();			// clear Input text box first time
			Global.runTextIn.Text = "InputText: ";
			Global.runTextIn.SelectionStart = Global.runTextIn.Text.Length;
			MultiID.nL = Environment.NewLine;
			MultiID.nL2 = MultiID.nL + MultiID.nL;
			ClearOutput();
			new Calc(iMaxDigits);				// initialize class Calc
			if (Global.command != "" && !Global.parmsDone)
			{
				MultiID.WriteTLn2("Command line was: " + Global.command);
				string st;
				GetParms(out st);				// get parameters from command line and
				Calculate(ref st);				// use them as a Calc command line
			}
			Common.running = false;
			labelRunning.Text = "";
			Common.DoubleSpace();
			Global.runTextIn.Focus();
		} // Run

		private void buttonCalculate_Click(object sender, System.EventArgs e)
		// calculate with input from the text input box
		{
			buttonCalculate_Click();
		}

		private void buttonCalculate_Click()		// calculate with input from the text input box
		{
		ResumeCalcAfterError:
			try
			{
				if (Common.running) return;			// don't call Calc() again till its returns
				Global.runTextIn.Focus();
				string st = Global.runTextIn.Text;	// get command input
				st = st.Trim();						// trim leading and trailing white space
				ClearInput();
				if (st != "")
				{
					Calculate(ref st);
				}
			}
			catch (SystemException ex)
			{
				// -------- Trap for error handling
				long totalMemory = GC.GetTotalMemory(false);
				string st = ex.Message + ", Memory used = " + totalMemory;
				DialogResult key = MessageBox.Show("Calc: Run-time error\n" + st,
					Global.title,
					MessageBoxButtons.OK,
					MessageBoxIcon.Exclamation); // display the error message.
				MultiID.muAbort = true;
				labelRunning.Text = "";
				Common.running = false;
				buttonSaveAll.Enabled = true;
				buttonRestoreAll.Enabled = true;
				menuItemRestart.Enabled = true;
				Calc.Cleanup();					// cleanup the named list
				goto ResumeCalcAfterError;
			}
		}

		public void Calculate(ref string st) // calculate with input from string st
		{
			Common.AddCom(st, " ");
			buttonSaveAll.Enabled = false;
			buttonRestoreAll.Enabled = false;
			menuItemRestart.Enabled = false;
			Common.running = true;
			MultiID.statReq = false;
			MultiID.statReq2 = false;
			MultiID.statReq3 = false;
			labelRunning.Text = "**Running**";
			// Common.comHL(1000000) = 1 // diag
			Common.RunCalc(st);
			labelRunning.Text = "";
			Common.running = false;
			buttonSaveAll.Enabled = true;
			buttonRestoreAll.Enabled = true;
			menuItemRestart.Enabled = true;
			FocusBothUs();
		}

		public static void FocusBothUs() // focus on input and output Run text boxes
		{
			Global.runTextOut.Select(Global.runTextOut.Text.Length, 0); // move to bottom/end of output text box
			Global.runTextOut.Focus();
			Global.runTextIn.Focus(); // move to Run input text box
		}

		private static void GetParms(out string st) // get parameters from command line if any
		// "C:\xxx\x xx\xxx.xPC" x=1234 allowed for
		{
			string st1 = "";
			string st2 = "";
			st = "";
			if (Global.parmsDone) return;
			Global.parmsDone = true;
			st = Global.command;
			Common.DelTabs(ref st);
			int i = st.IndexOf('"', 1);			// i = index of 2nd "
			if (st != "" && st[0] == '\"')	// if 1st character is a "
			{
				if (i < 0) return;				// Command = "... but no end " so exit
				int k = st.LastIndexOf('\\');	// Command = "..." ...
				if (k > 0)						// k points to last \
				{
					st1 = "ChDir(" + st.Substring(0, k+1) + "\")";	// st1 = ChDir("...\")
					Common.ReplaceAt(ref st, i, ' ');		// change second " to a blank space
					st = st.Substring(k + 1).Trim(' ');
				}
				else
				{
					st2 = st.Substring(1, i - 1).Trim(' ');	// still could be a comment
					if (Calc.GetFName(ref st2))
					{
						st = st.Substring(i+1).TrimStart(' ');
					}
				}
			}
			if (st2 == "")
			{
				i = st.IndexOf(' ');
				if (i < 0) i = st.Length;
				st2 = st.Substring(0, i);
				if (Calc.GetFName(ref st2))
				{
					Common.DelNPBls(ref st, i);
				}
			}
			st = (st1 + " " + (st2 + " " + st).TrimStart(' ')).TrimStart(' ');
			if (st != "")
			{
				Common.comHL[1] = st;	// store as first and only command in history
				Common.comPF[1] = " ";	// not protected
				Common.cComs = 1;
			}
		}

		private static void ClearInput() //Clear Input Screen
		{
			Global.runTextIn.Text = "";
		}

		public static void ClearOutput() // clear Output Screen
		{
			DateTimePicker dateTime = new DateTimePicker();
			string dateTimeString = dateTime.Value.ToString();
			Common.DoubleSpace(); // double space for the possible benefit of the log file
			Global.runTextOut.Text = "";
			MultiID.WriteLn2("Output Screen: Cleared " + dateTimeString);
			MultiID.WriteLn(Global.runTextOut, null, Global.title + ", " + Global.version);
			if (Global.system != "") MultiID.WriteLn("Run on: " + Global.system);
			MultiID.WriteLn();
			Global.runTextIn.Focus();
		}

		public static void HelpForm() // bring up the Help form
		{
			if (Global.helpUp < 3)			// allow at most 3 Help Forms up
			{
				HelpForm objHelpForm = new HelpForm();
				Global.runTextIn.Focus();	// restore Focus to Text input window
				objHelpForm.Show();
				objHelpForm.Help();			// call sub Help in the Help Form
			}
		}

		private void buttonAbortCalc_Click(object sender, System.EventArgs e)
		// respond to abort request if calc running
		{
			if (Common.running) MultiID.abortCalc = true;
			Global.runTextIn.Focus();
		}

		private void buttonClearLogFile_Click(object sender, System.EventArgs e)
		// clear and initialize the log file
		{
			Common.ClearLog();
			SetLogCaption();
			FocusBothUs();
		}

		private void buttonClearInput_Click(object sender, System.EventArgs e)
		// clear the input text box
		{
			Global.runTextIn.Text = "";
			Global.runTextIn.Focus(); // restore Focus to Text input window
		}

		private void buttonClearOutput_Click(object sender, System.EventArgs e)
		// clear the output text box
		{
			ClearOutput();
		}

		private void buttonLog_Click(object sender, System.EventArgs e)
		// toggle the log screen to log file option, same as the H command
		{
			Common.ToggleLogg();
			FocusBothUs();
		}

		private void buttonPause_Click(object sender, System.EventArgs e)
		// pause the calculations to free up the CPU
		{
			WaitForPause();
		}

		private void buttonQuit_Click(object sender, System.EventArgs e)
		// quit the Run form and go to Startup form
		{
			tQuitFlag = false;
			this.Close(); // memberFormClosing will do the work
		}

		private void buttonConfiguration_Click(object sender, System.EventArgs e)
		// bring up the configuration form
		{
			if (Common.configUp) return;
			ConfigForm objConfigForm = new ConfigForm();
			Global.runTextIn.Focus();	// restore Focus to Text input window
			objConfigForm.Show();
			objConfigForm.Config();		// call sub Config in the Config Form
		}

		private void buttonRestoreAll_Click(object sender, System.EventArgs e)
		// restore the configuration, same as the Restore command
		{
			if (Common.running) return;
			Common.DoubleSpace();
			Common.running = true;
			buttonRestoreAll.Enabled = false;
			buttonSaveAll.Enabled = false;
			Calc.ChkResSav(1, "");
			buttonRestoreAll.Enabled = true;
			buttonSaveAll.Enabled = true;
			Common.running = false;
			FocusBothUs();
		}

		private void buttonRestoreInput_Click(object sender, System.EventArgs e)
		// bring up the history form to restore operator input commands
		{
			if (Common.historyUp) return;
			HistoryForm objHistoryForm = new HistoryForm();
			Global.runTextIn.Focus(); // restore Focus to Text input window
			objHistoryForm.Show();
			objHistoryForm.History(); // call sub History in the History Form
		}

		private void buttonSaveAll_Click(object sender, System.EventArgs e)
		// save the configuration, same as the Save command
		{
			Common.DoubleSpace();
			if (Common.running) return;
			Common.running = true;
			buttonRestoreAll.Enabled = false;
			buttonSaveAll.Enabled = false;
			Calc.ChkResSav(2, "");
			buttonRestoreAll.Enabled = true;
			buttonSaveAll.Enabled = true;
			Common.running = false;
			FocusBothUs();
		}

		private void buttonStatusOfCalc_Click(object sender, System.EventArgs e)
		// request the status of the running calculation
		{
			if (Common.running)
			{
				MultiID.statReq = true;
				MultiID.statReq2 = true;
				MultiID.statReq3 = true;
			}
			FocusBothUs(); // catch all
		}

		private void menuItemAbout_Click(object sender, System.EventArgs e)
		// bring up information about this program
		{
			try
			{
				AboutForm aboutForm = new AboutForm();
				aboutForm.ShowDialog();
				if (aboutForm.DialogResult == DialogResult.Cancel)
				{
					aboutForm.Dispose();
				}
			}
			catch (Exception ex)
			{
				System.Console.WriteLine(ex.Message.ToString());
			}
		}

		private void menuItemExit_Click(object sender, System.EventArgs e)
		// quit the Run form and go to Startup form
		{
			tQuitFlag = true;
			this.Close(); // memberFormClosing will do the work
		}

		private void menuItemHelpForm_Click(object sender, System.EventArgs e)
		// display the Help form
		{
			Common.DoubleSpace();
			HelpForm();
		}

		private void menuItemPause_Click(object sender, System.EventArgs e)
		// respond to Pause request from menu
		{
			WaitForPause();
		}

		private void menuItemRestart_Click(object sender, System.EventArgs e)
		// reset the configuration and restart the calculator, same as the $ command
		{
			if (Common.running) return;
			Common.running = true;
			ClearOutput();
			new Calc();				// re-initialize class Calc
			Common.running = false;
		}

		public void SetLogCaption() // set log command button Caption
		{
			if (MultiID.logg)
			{
				if (buttonLog.Text != "Logging Is On")
					buttonLog.Text  = "Logging Is On";
			}
			else
			{
				if (buttonLog.Text != "Logging Is Off")
					buttonLog.Text  = "Logging Is Off";
			}
		}

		private void timerRun_Tick(object sender, System.EventArgs e)
		// don't hog the processor, but don't slowdown too much
		{
			if (Common.tQuitReq)
			{
				Common.tQuitReq = false;
				TotalQuit();
			}
			Application.DoEvents();	// process user requested actions;
		}

		private void FunctionKeys(object sender, KeyEventArgs e)
		// process requests from Function keys
		{
			if (e.KeyCode == Keys.Insert)		// display Insert mode
			{
				overtype = !overtype;
				if (overtype)
				{
					this.labelOvertype.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
					labelOvertype.Text = "Overtype On";
				}
				else
				{
					this.labelOvertype.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
					labelOvertype.Text = "Overtype Off";
				}
			}
			else if (e.KeyCode == Keys.F1)			// display the Help form
			{
				HelpForm();
			}
			else if (e.KeyCode == Keys.F2)		// quit program OR restart
			{
				if(Control.ModifierKeys != Keys.Control)
				{
					TotalQuit();				// F2 for quit and exit program
				}
				else
				{
					menuItemRestart_Click(sender, e);	// Ctrl+F2 for restart
				}
			}
			else if (e.KeyCode == Keys.F3)		// restore previous input command
			{
				RestoreF3();
			}
			else if (e.KeyCode == Keys.F4)		// restore previous input command and accept
			{
				RestoreF4();
			}
			else if (e.KeyCode == Keys.F5)		// get Status of calculation
			{
				buttonStatusOfCalc_Click(sender, e);
			}
			else if (e.KeyCode == Keys.F6)		// display Configuration form
			{
				buttonConfiguration_Click(sender, e);
			}
			else if (e.KeyCode == Keys.F7)		// display Restore Input History form
			{
				buttonRestoreInput_Click(sender, e);
			}
			else if (e.KeyCode == Keys.F8)		// accept input and Calculate
			{
				buttonCalculate_Click();
			}
			else if (e.KeyCode == Keys.F9)		// toggle Logging OR clear Log file
			{
				if(Control.ModifierKeys != Keys.Control)
				{
					buttonLog_Click(sender, e);	// F9 toggle Logging to Log file on/off
				}
				else
				{
					buttonClearLogFile_Click(sender, e);	// Ctrl+F9 clear Log file
				}
			}
			else if (e.KeyCode == Keys.F11)		// clear output TextBox OR clear input TextBox
			{
				if (Control.ModifierKeys != Keys.Control)
				{
					buttonClearOutput_Click(sender, e);	// F11 clear output TextBox
				}
				else
				{
					buttonClearInput_Click(sender, e);	// Ctrl+F11 clear input TextBox
				}
			}
			else if (e.KeyCode == Keys.F12)		// pause
			{
				buttonPause_Click(sender, e);
			}
			else if (e.KeyCode == Keys.O)
			{
				if(Control.ModifierKeys == Keys.Control)
				{
					buttonRestoreAll_Click(sender, e);	// Ctrl+O Restore All
				}
			}
			else if (e.KeyCode == Keys.S)
			{
				if(Control.ModifierKeys == Keys.Control)
				{
					buttonSaveAll_Click(sender, e);	// Ctrl+S Save All
				}
			}
			else if (e.KeyCode == Keys.Escape)	// interrupt/Abort a long calculation
			{
				if (Common.running)
				{
					MultiID.abortCalc = true;
					Global.runTextIn.Focus();
				}
				else
				{
					ClearInput();
				}
			}
		}

		private void richTextIn_KeyUp(object sender, KeyEventArgs e)
		// move to end of line in text input box
		{
			if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown)		// restore previous input command iComs
				Global.runTextIn.Select(Global.runTextIn.Text.Length, 0);	// go to end of line
		}

		private void richTextIn_KeyDown(object sender, KeyEventArgs e)
		// process requests from PgUp, PgDn, and Function keys
		{
			if (e.KeyCode == Keys.PageUp)			// restore previous input command iComs
			{
				Common.iComs = Math.Min(Common.iComs + 1, Common.cComs);
				// I wish to turn off PageUp.Beeper but how?
				e.Handled = true; // this is how!
			}
			else if (e.KeyCode == Keys.PageDown)	// restore previous input command iComs
			{
				Common.iComs = Math.Min(Common.iComs - 1, Common.cComs);
			}
			else
			{
				FunctionKeys(sender, e);
				return;
			}
			Common.iComs = Math.Max(Common.iComs, 1);
			if (Common.cComs > 0)
			{
				Global.runTextIn.Text = Common.comHL[Common.iComs];
			}
		}

		private void richTextOut_KeyDown(object sender, KeyEventArgs e)
		// function keys for output TextBox same as input TextBox
		{
			FunctionKeys(sender, e);
		}

		private void richTextIn_TextChanged(object sender, System.EventArgs e)
		// accept command input if linefeed at end of line
		// but not for continuation lines
		{
			string st = Global.runTextIn.Text.Trim(' '); // get command input
			int n = st.Length;
			if (n > 0)
			{
				if (st[n-1] == '\n')
				{
					if (n > 1)
					{
						if (st[n-2] == '-' || st[n-2] == '+')
						{
							return;
						}
					}
					buttonCalculate_Click();
				}
			}
		}

		public void TotalQuit() // check on request to totally Quit
		{
			if (Common.running) // if running, a Total quit request becomes an Abort request
			{
				MultiID.abortCalc = true;
			}
			else if (Common.tExitFlag)
			{
				tQuitFlag = true;
				this.Close(); // memberFormClosing will do the work
			}
			else
			{
				DialogResult key = MessageBox.Show(
					"Do you wish to totally Quit " + Global.pName + "?     \n\n" +
					"To Quit select OK or Hit Enter\n\n" +
					"To Cancel Quit select Cancel or\n" +
					"      Hit the ESC key\n",
					Global.title,
					MessageBoxButtons.OKCancel,
					MessageBoxIcon.Information); // display message.
				// ----------
				if (key == DialogResult.OK)
				{
					tQuitFlag = true;
					this.Close(); // memberFormClosing will do the work
				}
				Global.runTextIn.Focus();
			}
		}

		public void WaitForPause() // display Pause message box
		{
			buttonPause.Text = "OK";
			double TimeSaved = MultiID.TimerF(); // allow for time paused
			DialogResult key = MessageBox.Show(Global.pName + " is Paused. OK to Resume?",
				Global.title,
				MessageBoxButtons.OK,
				MessageBoxIcon.Information); // display message.
			// the Pause That Refreshes ----------
			buttonPause.Text = "Pause";
			double TimeOut = MultiID.TimerF() - TimeSaved; // allow for time-out
			MultiID.time0 += TimeOut;
			Global.runTextIn.Focus();
		}

		private void RunForm_Resize(object sender, System.EventArgs e) // resize the run form
		{
			int jTop = buttonQuit.Top + buttonQuit.Height + 18;
			int topHeight = 98;
			this.richTextIn.SetBounds(1, jTop, this.ClientRectangle.Width - 2, topHeight);
			this.richTextOut.SetBounds(1, jTop + topHeight + 2, this.ClientRectangle.Width - 2, this.ClientRectangle.Height - jTop - topHeight - 3);
		}

		private void memberFormClosing(object sender, System.ComponentModel.CancelEventArgs e)
		// the Run form is being closed so quit the Run form and go to Startup form
		// with .exe file, Close button click while running giver "Illegal operation"
		// so I put in a running test and a cancel
		{
			if (!MultiID.muAbort)
			{
				MultiID.muAbort = true;
				if (Common.running)
				{
					MultiID.WriteSLn("When **Running**, select Quit twice to quit");
					Global.runTextIn.Focus();
					e.Cancel = true; // cancel the Unload request
					return;
				}
			}
			if (MultiID.logg)
			{
				DateTimePicker dateTime = new DateTimePicker();
				string dateTimeString = dateTime.Value.ToString();
				MultiID.WriteLn("Log file \"" + Common.logFile + "\" Closed " + dateTimeString);
				MultiID.WriteLn(null, MultiID.outL);
				MultiID.outL.Close();
				MultiID.logg = false;
			}
			this.Hide();
			Global.runFormUp = false;
			if (tQuitFlag)
			{
				Dispose(true);
				objStartupForm.TotalQuit();
			}
			else
				objStartupForm.Show();
		}

		private void RestoreF3()
		{
			if (Common.cComs > 0)
			{
				Global.runTextIn.SelectionStart = 0;
				Global.runTextIn.Text = Common.comHL[Common.cComs];
				Global.runTextIn.SelectionStart = Common.comHL[Common.cComs].Length;
				Common.iComs = Common.cComs;
				Global.runTextIn.Focus();
			}
		}

		private void RestoreF4()
		{
			if (Common.cComs > 0)
			{
				Global.runTextIn.SelectionStart = 0;
				Global.runTextIn.Text = Common.comHL[Common.cComs];
				Global.runTextIn.SelectionStart = Common.comHL[Common.cComs].Length;
				buttonCalculate_Click();
			}
		}

		private void menuItemRestoreF3_Click(object sender, System.EventArgs e)
		{
			RestoreF3();
		}

		private void menuItemRestoreF4_Click(object sender, System.EventArgs e)
		{
			RestoreF4();
		}

		public void SetHelpHeight(int h) // set height of Run Form
		{
			helpHeight = h;
		}

		public void SetHistWidth(int w) // set width of Run Form
		{
			histWidth = w;
		}

		public void SetHistHeight(int h) // set height of Run Form
		{
			histHeight = h;
		}

		public void SetHelpWidth(int w) // set width of Run Form
		{
			helpWidth = w;
		}

		public void SetRunHeight(int h) // set height of Run Form
		{
			runHeight = h;
			this.Height = h;	// Resize the form
			this.CenterToScreen();
		}

		public void SetRunWidth(int w) // set width of Run Form
		{
			runWidth = w;
			this.Width = w;		// Resize the form
			this.CenterToScreen();
		}

		public void AddToTitle(String st) // add st to form title
		{
			this.Text += st;
		}

		public void DelFromTitle(String st) // delete st from form title
		{
			this.Text = this.Text.Substring(0, this.Text.Length - st.Length);
		}

		private void cbOnTop_Click(object sender, System.EventArgs e)
		{
			cbOnTop.Checked = !cbOnTop.Checked;
			this.TopMost = cbOnTop.Checked;
		}
		
		private bool tQuitFlag;				// total quit/exit flag
		// tQuitFlag helps implement the requirement that a close or menuItemExit will totally quit the
		// program while a Quit will go to the Startup form
		private StartupForm objStartupForm;

		public bool overtype;					// current state of overtype/insert mode
		public static int helpHeight = 520;		// current height of the Help Form in pixels
		public static int helpWidth = 690;		// current width of the Help Form in pixels
		public static int histHeight = 525;		// current height of the Help Form in pixels
		public static int histWidth = 704;		// current width of the Help Form in pixels
		public static int runHeight = 564;		// current height of the Run Form in pixels
		public static int runWidth = 674;		// current width of the Run Form in pixels
	}
}
