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

📄 settings.cs

📁 常见的串口通信程序
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace SerialPorts
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class Settings : Form
    {
        // Methods
        public Settings(string fileName, SerialCnfg cfg)
        {
            this.InitializeComponent();
            this.PortBox.Items.Add(cfg.PortName);
            this.PortBox.SelectedIndex = 0;
            this.EnumLoad(typeof(LineSpeed), this.BaudBox, cfg.BaudRate);
            this.EnumLoad(typeof(ByteSize), this.DataBox, cfg.DataBits);
            this.EnumLoad(typeof(StopBits), this.StopBox, cfg.StopBits);
            this.EnumLoad(typeof(Parity), this.ParityBox, cfg.Parity);
            this.EnumLoad(typeof(Handshake), this.HshakeBox, cfg.FlowCtrl);
            this.LoadCtrl(this.XonBox, cfg.XonChar);
            this.LoadCtrl(this.XoffBox, cfg.XoffChar);
            this.LoadChar(this.EofBox, cfg.EofChar);
            this.LoadChar(this.EventBox, cfg.EvtChar);
            this.LoadChar(this.ErrorBox, cfg.ErrChar);
            this.ChkEvent.Checked = cfg.ReceiveMode || false;
            this.ChkParity.Checked = cfg.ErrReplace || false;
            this.ChkDiscard.Checked = cfg.NullDiscard || false;
            Application.DoEvents();
            base.Focus();
            this.config = cfg;
            this.fileName = fileName;
            this.changed = false;
        }

        private void ChangeHandler(object sender, EventArgs e)
        {
            this.changed = true;
        }

        private void CmdCancel_Click(object sender, EventArgs e)
        {
            if (this.changed)
            {
                Confirm confirm1 = new Confirm();
                if (!confirm1.Display("Confirm Close", "The Settings Were Changed.Are You Sure You Want To Discard All Changes?", 1))
                {
                    return;
                }
            }
            base.Close();
        }

        private void CmdSave_Click(object sender, EventArgs e)
        {
            this.UpdateConfig();
            this.config.Save(this.fileName);
            this.changed = false;
            base.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private object EnumFind(Type type, string member)
        {
            object obj1;
            try
            {
                obj1 = Enum.Parse(type, member);
            }
            catch
            {
                obj1 = null;
            }
            return obj1;
        }

        private void EnumLoad(Type type, ComboBox cb, object obj)
        {
            try
            {
                string[] textArray1 = Enum.GetNames(type);
                for (int num1 = 0; num1 < textArray1.Length; num1++)
                {
                    cb.Items.Add(Enum.Parse(type, textArray1[num1]));
                }
                cb.SelectedIndex = this.FindMatch(cb, obj);
            }
            catch
            {
            }
        }

        private int FindMatch(ComboBox cb, object obj)
        {
            if (obj != null)
            {
                int num1 = 0;
                IEnumerator enumerator1 = cb.Items.GetEnumerator();
                try
                {
                    while (enumerator1.MoveNext())
                    {
                        if (Convert.ToInt32(enumerator1.Current) == Convert.ToInt32(obj))
                        {
                            return num1;
                        }
                        num1++;
                    }
                }
                finally
                {
                    IDisposable disposable1 = enumerator1 as IDisposable;
                    if (disposable1 != null)
                    {
                        disposable1.Dispose();
                    }
                }
            }
            return 0;
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.CmdSave = new Button();
            this.CmdCancel = new Button();
            this.panel7 = new Panel();
            this.ChkParity = new CheckBox();
            this.label7 = new Label();
            this.ErrorBox = new ComboBox();
            this.ChkDiscard = new CheckBox();
            this.ChkEvent = new CheckBox();
            this.label13 = new Label();
            this.EventBox = new ComboBox();
            this.label12 = new Label();
            this.EofBox = new ComboBox();
            this.label11 = new Label();
            this.XoffBox = new ComboBox();
            this.label10 = new Label();
            this.XonBox = new ComboBox();
            this.label6 = new Label();
            this.HshakeBox = new ComboBox();
            this.label5 = new Label();
            this.ParityBox = new ComboBox();
            this.label4 = new Label();
            this.StopBox = new ComboBox();
            this.label3 = new Label();
            this.DataBox = new ComboBox();
            this.label2 = new Label();
            this.label1 = new Label();
            this.BaudBox = new ComboBox();
            this.PortBox = new ComboBox();
            this.toolTip = new ToolTip(this.components);
            this.panel7.SuspendLayout();
            base.SuspendLayout();
            this.CmdSave.Location = new Point(0xe0, 240);
            this.CmdSave.Name = "CmdSave";
            this.CmdSave.Size = new Size(0x60, 30);
            this.CmdSave.TabIndex = 1;
            this.CmdSave.Text = "\u4fdd\u5b58\u8bbe\u7f6e";
            this.CmdSave.Click += new EventHandler(this.CmdSave_Click);
            this.CmdCancel.Location = new Point(0x160, 240);
            this.CmdCancel.Name = "CmdCancel";
            this.CmdCancel.Size = new Size(0x60, 30);
            this.CmdCancel.TabIndex = 2;
            this.CmdCancel.Text = "\u53d6  \u6d88";
            this.CmdCancel.Click += new EventHandler(this.CmdCancel_Click);
            this.panel7.BorderStyle = BorderStyle.Fixed3D;
            this.panel7.Controls.Add(this.ChkParity);
            this.panel7.Controls.Add(this.label7);
            this.panel7.Controls.Add(this.ErrorBox);
            this.panel7.Controls.Add(this.ChkDiscard);
            this.panel7.Controls.Add(this.ChkEvent);
            this.panel7.Controls.Add(this.label13);
            this.panel7.Controls.Add(this.EventBox);
            this.panel7.Controls.Add(this.label12);
            this.panel7.Controls.Add(this.EofBox);
            this.panel7.Controls.Add(this.label11);
            this.panel7.Controls.Add(this.XoffBox);
            this.panel7.Controls.Add(this.label10);
            this.panel7.Controls.Add(this.XonBox);
            this.panel7.Location = new Point(0x100, 8);
            this.panel7.Name = "panel7";
            this.panel7.Size = new Size(0xc0, 0xd8);
            this.panel7.TabIndex = 14;
            this.ChkParity.Location = new Point(0x10, 0x20);
            this.ChkParity.Name = "ChkParity";
            this.ChkParity.Size = new Size(0x80, 0x17);
            this.ChkParity.TabIndex = 0x29;
            this.ChkParity.Text = "\u66ff\u6362\u5947\u5076\u9519\u8bef";
            this.toolTip.SetToolTip(this.ChkParity, "Replace each char with an error with the Error Char (set below).");
            this.ChkParity.CheckedChanged += new EventHandler(this.ChangeHandler);
            this.label7.Location = new Point(0x30, 0xb8);
            this.label7.Name = "label7";
            this.label7.Size = new Size(0x30, 0x16);
            this.label7.TabIndex = 40;
            this.label7.Text = "Error";
            this.label7.TextAlign = ContentAlignment.MiddleRight;
            this.ErrorBox.Location = new Point(0x68, 0xb8);
            this.ErrorBox.Name = "ErrorBox";
            this.ErrorBox.Size = new Size(0x40, 20);
            this.ErrorBox.TabIndex = 0x27;
            this.toolTip.SetToolTip(this.ErrorBox, "Parity error replacement char.");
            this.ErrorBox.SelectedIndexChanged += new EventHandler(this.ChangeHandler);
            this.ChkDiscard.Location = new Point(0x10, 0x10);
            this.ChkDiscard.Name = "ChkDiscard";
            this.ChkDiscard.Size = new Size(0x80, 0x17);
            this.ChkDiscard.TabIndex = 0x25;
            this.ChkDiscard.Text = "\u63a5\u6536\u4e22\u5f03 NULs";
            this.toolTip.SetToolTip(this.ChkDiscard, "Throw away all NULL chars received.");
            this.ChkDiscard.CheckedChanged += new EventHandler(this.ChangeHandler);
            this.ChkEvent.Location = new Point(0x10, 0);
            this.ChkEvent.Name = "ChkEvent";
            this.ChkEvent.Size = new Size(0x80, 0x17);
            this.ChkEvent.TabIndex = 0x24;

⌨️ 快捷键说明

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