1、打开串口
cs
private void button1_Click(object sender, EventArgs e)
{
myPort = cmb1.Text;
mybaud = Convert.ToInt32(cmb2.Text, 10);
databit = 8;
parity = Parity.None;
stopBit = StopBits.One;
textBox9.Text = "2";
try
{
sp = new SerialPort(myPort, mybaud, parity, databit, stopBit);
if (!sp.IsOpen) sp.Open();
button1.Enabled = false;
button2.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示!");
}
}
2、弹窗如何显示
cs
MessageBox.Show("串口还没有打开!", "提示!");
3、修改按钮的颜色
cpp
button_Start.Text = "停 止";
button_Start.BackColor = System.Drawing.Color.LightGreen;
4、如何显示实时时间
方法一:
1、创建好项目后先从工具箱拖拽一个TextBox,命名为Timer123,然后从工具箱拖拽一个timer的控件,在右下角的属性栏中进行修改2个属性(Enable设置为True;Interval设置为1000(代表一秒))。

2、显示时间
cs
private void timer1_Tick(object sender, EventArgs e)
{
this.Timer123.Text = DateTime.Now.ToString();
}
方法二:
cs
Timer mytimer;
mytimer = new Timer();
mytimer.Enabled = true;
mytimer.Interval = 1000;
mytimer.Tick += new EventHandler(mytimer_Tick);
void mytimer_Tick(object sender, EventArgs e)
{
textBox2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
5、如何切换多个界面
选择 tabControl选项卡

可以添加多个界面

tabControl可以嵌套

可以修改选项卡名字,点击集合右边的三个点

修改Text文本内容即可

6、下拉框
工具栏中找到ComboBox控件拖出,右键编辑项即可查看编辑下拉框可以选择内容

7、checkedListBox多选框控件
工具栏搜索check,勾选控件到桌面

右键选择编辑项然后在编辑选项即可

checkedListBox1.SetItemChecked(1, false);可以让选项被选中或者被取消,第一个参数是第几个选项,从0开始,第二个参数为true则表示被选中,否则没有被选中
8、如何去除因为双击控件而出现的引用函数
因为我双击了textBox1控件,此时弹到了此界面,但是这个函数我不使用,删除之后又会报错

解决办法:跳转到引用的地方删除即可

9、textBox控件
首先在工具框中选择TextBox按键,然后设置背景颜色,最后当选中右边的某行时,最下面会提示该参数的含义,比如BorderStyle指示编辑控件是否应带有边框,如果选择无则是左边的形态
