⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 termform.cs

📁 微软C#读写类
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.buttonImm.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.buttonImm.Location = new System.Drawing.Point(344, 8);
			this.buttonImm.Name = "buttonImm";
			this.buttonImm.TabIndex = 16;
			this.buttonImm.Tag = "0";
			this.buttonImm.Text = "Queued";
			this.buttonImm.Click += new System.EventHandler(this.buttonImm_Click);
			// 
			// TermForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(426, 254);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.buttonImm,
																		  this.groupBox1,
																		  this.buttonClr,
																		  this.textBoxR,
																		  this.buttonSet,
																		  this.buttonStatus,
																		  this.buttonO,
																		  this.textBoxS});
			this.KeyPreview = true;
			this.MinimumSize = new System.Drawing.Size(434, 180);
			this.Name = "TermForm";
			this.Text = "CommBase Terminal";
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form_KeyDown);
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form_KeyPress);
			this.Load += new System.EventHandler(this.BaseTermForm_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

	private void Form_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
	{
		byte c;
		c = (byte)e.KeyChar;
		if ((c == 13) && (!inEscape))
		{
			textBoxS.AppendText("<CR>");
			BaseTerm.term.SendCtrl("CR");
			return;
		}
		if ((c < 0x20) || (c > 0x7E)) return;
		if (inEscape)
		{
			if (c == (byte)'<')
			{
				BaseTerm.term.SendChar(c);
				textBoxS.Text = mark;
				inEscape = false;
				textBoxS.BackColor = Color.White;
			}
			else
			{
				if (c == (byte)'>')
				{
					if (!BaseTerm.term.SendCtrl(esc))
					{
						textBoxS.Text = mark;
						c = 0;
					}
					inEscape = false;
					textBoxS.BackColor = Color.White;
				} 
				else 
				{
					esc += ((char)c).ToString();
				}
			}
		} 
		else 
		{
			if (c == (byte)'<')
			{
				inEscape = true;
				esc = "";
				mark = textBoxS.Text;
				textBoxS.BackColor = Color.Yellow;
			}
			else
			{
				BaseTerm.term.SendChar(c);
			}
		}
		if (c >= (byte)' ') textBoxS.AppendText(e.KeyChar.ToString());
		e.Handled = true;
	}

	private void buttonO_Click(object sender, System.EventArgs e)
	{
		if (buttonO.Tag.ToString() == "1")
		{
			BaseTerm.term.Close();
			buttonO.Tag = "0";
			buttonO.Text = "Offline";
		}
		else
		{
			try
			{
				if (BaseTerm.term.Open())
				{
					ShowMsg(">>>> ONLINE");
					buttonO.Tag = "1";
					buttonO.Text = "Online";
				}
				else
				{
					ShowMsg(">>>> PORT UNAVAILABLE");
				}
			}
			catch (CommPortException ex)
			{
				ShowException(ex);
			}
		}
		textBoxS.Focus();
	}

	public void ShowChar(string s, bool nl)
	{
		textBoxR.AppendText(s);
		if (nl)	textBoxR.AppendText("\r\n");
	}

	public void ShowMsg(string s)
	{
		Color c = textBoxR.SelectionColor;
		textBoxR.SelectionColor = Color.Green;
		textBoxR.AppendText("\r\n" + s + "\r\n");
		textBoxR.SelectionColor = c;
	}

	public void ShowException(CommPortException e)
	{
		Color c = textBoxR.SelectionColor;
		textBoxR.SelectionColor = Color.Red;
		textBoxR.AppendText("\r\n>>>> EXCEPTION\r\n");
		textBoxR.SelectionColor = Color.Red;
		textBoxR.AppendText(e.Message);
		if (e.InnerException != null)
		{
			textBoxR.AppendText("\r\n");
			textBoxR.SelectionColor = Color.Red;
			textBoxR.AppendText(e.InnerException.Message);
		}
		textBoxR.SelectionColor = Color.Red;
		textBoxR.AppendText("\r\n>>>> END EXCEPTION\r\n");
		textBoxR.SelectionColor = c;
	}

	public void SetIndics(bool CTS, bool DSR, bool RLSD, bool Rng)
	{
		radioButtonCTS.Checked = CTS;
		radioButtonDSR.Checked = DSR;
		radioButtonRLSD.Checked = RLSD;
		radioButtonRng.Checked = Rng;
	}

	private void Form_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
	{
		if (e.KeyCode == Keys.Back)
		{
			textBoxS.Text = "";
			e.Handled = true;
		}
		if (e.KeyCode == Keys.Delete)
		{
			textBoxS.Text = "";
			textBoxR.Text = "";
			e.Handled = true;
		}
	}

	private void checkBox_CheckedChanged(object sender, System.EventArgs e)
	{
		BaseTerm.term.OPClick((CheckBox)sender);
	}

	public void OnClose()
	{
		textBoxR.BackColor = Color.LightGray;

		buttonStatus.Enabled = false;
		buttonSet.Enabled = true;

		radioButtonCTS.Checked = false;
		radioButtonDSR.Checked = false;
		radioButtonRLSD.Checked = false;
		radioButtonRng.Checked = false;
		checkBoxRTS.Checked = false;
		checkBoxDTR.Checked = false;
		checkBoxBK.Checked = false;

		radioButtonCTS.Enabled = false;
		radioButtonDSR.Enabled = false;
		radioButtonRLSD.Enabled = false;
		radioButtonRng.Enabled = false;
		checkBoxRTS.Enabled = false;
		checkBoxDTR.Enabled = false;
		checkBoxBK.Enabled = false;
		buttonO.Tag = "0";
		buttonO.Text = "Offline";
	}

	public void OnOpen()
	{
		buttonO.Tag = "1";
		buttonO.Text = "Online";
		radioButtonCTS.Enabled = true;
		radioButtonDSR.Enabled = true;
		radioButtonRLSD.Enabled = true;
		radioButtonRng.Enabled = true;
		BaseTerm.term.setOPTicks(checkBoxDTR);
		BaseTerm.term.setOPTicks(checkBoxRTS);
		BaseTerm.term.setOPTicks(checkBoxBK);
		buttonStatus.Enabled = true;
		buttonSet.Enabled = false;
		textBoxR.BackColor = Color.White;
	}

	private void buttonStatus_Click(object sender, System.EventArgs e)
	{
		BaseTerm.term.ShowInfo();
		textBoxS.Focus();
	}

	private void buttonSet_Click(object sender, System.EventArgs e)
	{
		BaseTerm.term.Settings();
		textBoxS.Focus();
	}

	private void buttonClr_Click(object sender, System.EventArgs e)
	{
		textBoxS.Text = "";
		textBoxR.Text = "";
		inEscape = false;
		esc = "";
		mark = "";
		textBoxS.BackColor = Color.White;
		textBoxS.Focus();
	}

	private void BaseTermForm_Load(object sender, System.EventArgs e)
	{
		if (BaseTerm.settingsFileName == "")
			this.Text = "CommBase Terminal";
		else
			this.Text = "CommBase Terminal [" + BaseTerm.settingsFileName + "]";
		textBoxS.Focus();
	}

	private void buttonImm_Click(object sender, System.EventArgs e)
	{
		if (buttonImm.Tag.ToString() == "0")
		{
			buttonImm.Tag = "1";
			buttonImm.Text = "Immediate";
			BaseTerm.term.Immediate = true;
		}
		else
		{
			buttonImm.Tag = "0";
			buttonImm.Text = "Queued";
			BaseTerm.term.Immediate = false;
		}
		textBoxS.Focus();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -