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

📄 frmcommconfig.cs

📁 该项目实现在.net 2003上
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SmartE1Analyzer
{
	/// <summary>
	/// frmCommConfig 的摘要说明。
	/// </summary>
	public class frmCommConfig : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label lblCommNo;
		private System.Windows.Forms.Label lblBaud;
		private System.Windows.Forms.Label lblDataNum;
		private System.Windows.Forms.Label lblStopNum;
		private System.Windows.Forms.Label lblCheck;
		private System.Windows.Forms.ComboBox comboComNo;
		private System.Windows.Forms.ComboBox comboBaud;
		private System.Windows.Forms.ComboBox comboDataBitNum;
		private System.Windows.Forms.ComboBox comboStopBitNum;
		private System.Windows.Forms.ComboBox comboCheck;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button btnCancel;

	    private frmMain m_ParentFrm;//父窗口引用
		public frmCommConfig(frmMain frmmain)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			this.m_ParentFrm = frmmain;
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.comboCheck = new System.Windows.Forms.ComboBox();
			this.comboStopBitNum = new System.Windows.Forms.ComboBox();
			this.comboDataBitNum = new System.Windows.Forms.ComboBox();
			this.comboBaud = new System.Windows.Forms.ComboBox();
			this.comboComNo = new System.Windows.Forms.ComboBox();
			this.lblCheck = new System.Windows.Forms.Label();
			this.lblStopNum = new System.Windows.Forms.Label();
			this.lblDataNum = new System.Windows.Forms.Label();
			this.lblBaud = new System.Windows.Forms.Label();
			this.lblCommNo = new System.Windows.Forms.Label();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.comboCheck);
			this.panel1.Controls.Add(this.comboStopBitNum);
			this.panel1.Controls.Add(this.comboDataBitNum);
			this.panel1.Controls.Add(this.comboBaud);
			this.panel1.Controls.Add(this.comboComNo);
			this.panel1.Controls.Add(this.lblCheck);
			this.panel1.Controls.Add(this.lblStopNum);
			this.panel1.Controls.Add(this.lblDataNum);
			this.panel1.Controls.Add(this.lblBaud);
			this.panel1.Controls.Add(this.lblCommNo);
			this.panel1.Location = new System.Drawing.Point(24, 32);
			this.panel1.Size = new System.Drawing.Size(192, 152);
			// 
			// comboCheck
			// 
			this.comboCheck.Items.Add("无校验");
			this.comboCheck.Items.Add("奇校验");
			this.comboCheck.Items.Add("偶校验");
			this.comboCheck.Location = new System.Drawing.Point(64, 112);
			this.comboCheck.Size = new System.Drawing.Size(88, 20);
			//this.comboCheck.SelectedIndexChanged += new System.EventHandler(this.comboCheck_SelectedIndexChanged);
			// 
			// comboStopBitNum
			// 
			this.comboStopBitNum.Items.Add("1");
			this.comboStopBitNum.Items.Add("1.5");
			this.comboStopBitNum.Items.Add("2");
			this.comboStopBitNum.Location = new System.Drawing.Point(64, 88);
			this.comboStopBitNum.Size = new System.Drawing.Size(88, 20);
			// 
			// comboDataBitNum
			// 
			this.comboDataBitNum.Items.Add("5");
			this.comboDataBitNum.Items.Add("6");
			this.comboDataBitNum.Items.Add("7");
			this.comboDataBitNum.Items.Add("8");
			this.comboDataBitNum.Location = new System.Drawing.Point(64, 64);
			this.comboDataBitNum.Size = new System.Drawing.Size(88, 20);
			// 
			// comboBaud
			// 
			this.comboBaud.Items.Add("9600");
			this.comboBaud.Items.Add("19200");
			this.comboBaud.Items.Add("38400");
			this.comboBaud.Items.Add("115200");
			this.comboBaud.Location = new System.Drawing.Point(64, 40);
			this.comboBaud.Size = new System.Drawing.Size(88, 20);
			// 
			// comboComNo
			// 
			this.comboComNo.Items.Add("com1");
			this.comboComNo.Items.Add("com2");
			this.comboComNo.Items.Add("com3");
			this.comboComNo.Items.Add("com4");
			this.comboComNo.Items.Add("com5");
			this.comboComNo.Items.Add("com6");
			this.comboComNo.Items.Add("com7");
			this.comboComNo.Items.Add("com8");
			this.comboComNo.Items.Add("com9");
			this.comboComNo.Items.Add("com10");
			this.comboComNo.Location = new System.Drawing.Point(64, 16);
			this.comboComNo.Size = new System.Drawing.Size(88, 20);
			//this.comboComNo.SelectedIndexChanged += new System.EventHandler(this.comboComNo_SelectedIndexChanged);
			// 
			// lblCheck
			// 
			this.lblCheck.Location = new System.Drawing.Point(16, 114);
			this.lblCheck.Size = new System.Drawing.Size(48, 16);
			this.lblCheck.Text = "校  验";
			// 
			// lblStopNum
			// 
			this.lblStopNum.Location = new System.Drawing.Point(16, 92);
			this.lblStopNum.Size = new System.Drawing.Size(48, 16);
			this.lblStopNum.Text = "停止位";
			// 
			// lblDataNum
			// 
			this.lblDataNum.Location = new System.Drawing.Point(16, 68);
			this.lblDataNum.Size = new System.Drawing.Size(56, 16);
			this.lblDataNum.Text = "数据位";
			// 
			// lblBaud
			// 
			this.lblBaud.Location = new System.Drawing.Point(16, 45);
			this.lblBaud.Size = new System.Drawing.Size(48, 16);
			this.lblBaud.Text = "波特率";
			// 
			// lblCommNo
			// 
			this.lblCommNo.Location = new System.Drawing.Point(16, 21);
			this.lblCommNo.Size = new System.Drawing.Size(48, 16);
			this.lblCommNo.Text = "串口号";
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(96, 216);
			this.btnOK.Size = new System.Drawing.Size(56, 24);
			this.btnOK.Text = "确定[&Y]";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(168, 216);
			this.btnCancel.Size = new System.Drawing.Size(56, 24);
			this.btnCancel.Text = "取消[&C]";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(22, 11);
			this.label1.Size = new System.Drawing.Size(98, 16);
			this.label1.Text = "串口参数设置:";
			// 
			// frmCommConfig
			// 
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.panel1);
			this.Text = "串口参数设置";
			this.Load += new System.EventHandler(this.frmCommConfig_Load);

		}
		#endregion

		private void frmCommConfig_Load(object sender, System.EventArgs e)
		{
			//
			this.comboComNo.Text = "com" + this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.ComNo.ToString();
			this.comboBaud.Text = this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.BaudRate.ToString();
			this.comboDataBitNum.Text = "8";
			this.comboStopBitNum.Text = "1";
			if(this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.Parity == 0)
				this.comboCheck.Text = "无校验";
			else if(this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.Parity == 1)
    			this.comboCheck.Text = "奇校验";
			else if(this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.Parity == 2)
				this.comboCheck.Text = "偶校验";
			else
				this.comboCheck.Text = "无校验";
			//
			Rectangle screen = Screen.PrimaryScreen.Bounds;
			this.Location = new Point((screen.Width - this.Width) / 2,
				(screen.Height - this.Height ) / 2);

		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.ComNo = this.comboComNo.SelectedIndex + 1;
			switch(this.comboBaud.SelectedIndex)
			{
				case 0:
					this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.BaudRate = 9600;
					break;
				case 1:
					this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.BaudRate = 19200;
					break;
				case 2:
					this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.BaudRate = 38400;
					break;
				case 3:
					this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.BaudRate = 115200;
					break;
				default:
					this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.BaudRate = 19200;
					break;
 
			}
			this.m_ParentFrm.m_EquipAndPerformInfo.m_CommConfigParam.Parity = this.comboCheck.SelectedIndex;
			
			this.Close();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		
	}
}

⌨️ 快捷键说明

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