从form1到form2的数据导航 [英] form1 to form2 data nevigation

查看:56
本文介绍了从form1到form2的数据导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想进行串行连接,而这部分我在form1上完成了,但是之后
在Form2上可用的文本框中的下一个传入数据位置.所有设置(如波特率,端口号)均在form1中完成,此任务完成后将出现一个连接按钮(在form1中)(form2任务).为此,任何人都可以帮助我

basically i want do serial connection and this part i am completed on form1 but after that
the the next incoming data place in text box which is available on form2. all settings like baud rate,port no are done in form1 and there is one connect button(in form1) after that this task will be completed(form2 task). for this can any one help me

推荐答案

在您的Form1实例中设置并连接串行端口.通过Form2中的公共属性或通过构造函数,将其传递给您的Form2实例以完成工作.



如果您愿意,可以给我示例代码吗"

这并不完全困难...
试试:
Set up and connect the Serial Port in your Form1 instance. Pass that through to you Form2 instance for it to do the work, either through a public property in Form2, or via the constructor.



"Can you Give Me sample code for this if you hve"

It''s not exactly difficult...
Try:
SerialPort mySerialPort;
private void button1_Click(object sender, EventArgs e)
    {
    using (mySerialPort = new SerialPort("COM3"))
        {
        mySerialPort.BaudRate = 9600;
        mySerialPort.DataBits = 8;
        mySerialPort.Open();
        MyProcessingForm mpf = new MyProcessingForm();
        mpf.SerialPort = mySerialPort;
        mpf.ShowDialog();
        mySerialPort.Close();
        }
   }

或:

SerialPort mySerialPort;
private void button1_Click(object sender, EventArgs e)
    {
    using (mySerialPort = new SerialPort("COM3"))
        {
        mySerialPort.BaudRate = 9600;
        mySerialPort.DataBits = 8;
        mySerialPort.Open();
        MyProcessingForm mpf = new MyProcessingForm(mySerialPort);
        mpf.ShowDialog();
        mySerialPort.Close();
        }
   }

我?我可能会选择第二个版本...

Me? I''d probably go with the second version...


http://msdn.microsoft.com/en-us/library/ms171925.aspx#Y2400[^]. The Above link will guide you in step by Step.


这篇关于从form1到form2的数据导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆