相同的serialport我有两种形式= Form1.cs和第一表上SMS.CS (Form1中)我已配置并准备工作serialport1。我有一个叫做发送消息的按钮。此按钮打开称为SMS.cs的新窗体。使用上两种不同的形式
private void SMS_Click(object sender, EventArgs e)
{
SMS settings = new SMS();
settings.ShowDialog();
}
我想使用我配置的serialport1上窗体:Form1和窗体SMS.cs.这也可以从手机短信的形式接收数据,并使用serialport1发送Form1上,例如:
private void SMS_Click(object sender, EventArgs e)
{
SMS settings = new SMS();
settings.ShowDialog();
SerialPort1.Writeln(Data from form SMS)
}
,但我不知道该怎么做。在我看来,最好的办法是直接从短信形式发送数据的..
编辑:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public partial class SMSForm : Form
{
SerialPort SerialP;
public SMSForm(Object SerialP)
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SerialP.WriteLine("ATI");
}
}
}
我早些时候试图通过这种方式,但有错误:错误CS1729:“WindowsFormsApplication1.SMSForm”不包含一个构造函数1个参数 – Elfoc 2011-06-11 15:08:57
@Elfoc:告诉我们你是如何定义构造函数的。错误信息表明你没有... – Andrei 2011-06-11 15:20:17
我没有这样做:)在编辑我试图定义这个构造函数,但有问题:)我只有更多的时间基础知识.. :( – Elfoc 2011-06-11 15:38:05