C#上位机——串口助手
第一步:布局
第二步:设置属性
第三步:编写逻辑
初始化文本
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 串口助手
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//给下拉列表添加端口
this.port_cbb.Items.Add("COM5");//this代表窗口
this.port_cbb.Items.Add("COM6");
//给发送框添加预设文本 也就是初始化
this.send_txb.Text = "我是发送框";
//给接收框添加预设文本
this.recive_rtb.Text = "我是接收框";
}
}
}
点击按钮事件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 串口助手
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//给下拉列表添加端口
this.port_cbb.Items.Add("COM5");//this代表窗口
this.port_cbb.Items.Add("COM6");
//给发送框添加预设文本 也就是初始化
this.send_txb.Text = "我是发送框";
//给接收框添加预设文本
this.recive_rtb.Text = "我是接收框";
}
private void button1_Click(object sender, EventArgs e)
{
//如果发送的数据不为空,则接收
if (this.send_txb.Text != "")
{
this.recive_rtb.AppendText(this.send_txb.Text);
}
else
{
MessageBox.Show("请先输入发送数据");
}
}
}
}