嗨,代码如下所示...
试图从 com 端口读取数据并将秤发送到文本框中的重量显示到文本框中,我收到一条错误消息 -
WindowsFormsApplication1.Form1.textBox1_TextChanged(object, System.EventArgs)' 必须声明一个主体,因为它没有标记为抽象、外部或部分
我是 C# 新手,请帮忙
private void textBox1_TextChanged(object sender, EventArgs e);
}
namespace Read_serial
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DtrEnable = true;
serialPort1.Open();
serialPort1.DataReceived += serialPort1_DataReceived;
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string line = serialPort1.ReadLine();
this.BeginInvoke(new LineReceivedEvent(LineReceived), line);
}
private delegate void LineReceivedEvent(string line);
private void LineReceived(string line)
{
//What to do with the received line here
textBox1.Text = line;
progressBar1.Value = int.Parse(line);
}
}
}
}