C#引用一例Form2调用Form1的函数包含 serialPort1.Write时

来源:互联网 发布:桌面网络图标不见了 编辑:程序博客网 时间:2024/05/26 02:55

Form2调用Form1的函数包含

serialPort.Write(xx,x,x);时

不要用控件

自己写public static SerialPort serialPort1 = new SerialPort();


控件

public System.IO.Ports.SerialPort serialPort1;

改为

public Static System.IO.Ports.SerialPort serialPort1;

同时

this.serialPort1 = new System.IO.Ports.SerialPort(this.components);

改为

serialPort1 = new System.IO.Ports.SerialPort(this.components);

删除this

以上控件修改方法会自动复位为修改前,所以不能用控件


0 0