settingsform.cs

来自「Bluetooth Simulation in C# with Serial P」· CS 代码 · 共 46 行

CS
46
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace CSSP
{
    public partial class SettingsForm : Form
    {
        private string  inboundPort;
        private string outboundPort;
        public SettingsForm(string inbound,string outbound)
        {
            InitializeComponent();
            inboundPort = inbound;
            outboundPort = outbound;
            string[] ports = SerialPort.GetPortNames();
            comboBox1.Items.Add("NO PORT SELECTED");
            for (int i = 0; i < ports.Length; i++)
                comboBox1.Items.Add(ports[i]);
            comboBox2.Items.Add("NO PORT SELECTED");
            for (int i = 0; i < ports.Length; i++)
                comboBox2.Items.Add(ports[i]);
            if (comboBox1.Items.Contains(inboundPort))
                comboBox1.SelectedItem=inboundPort;
            else
                comboBox1.SelectedIndex = 0;
            if (comboBox2.Items.Contains(outboundPort))
                comboBox2.SelectedItem=outboundPort;
            else
                comboBox2.SelectedIndex = 0;
          
        }
        public string GetInboundPort()
        {
            return (string)comboBox1.SelectedItem;
        }
        public string GetOutboundPort()
        {
            return (string)comboBox2.SelectedItem;
        }
    }
}

⌨️ 快捷键说明

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