形成通信的形式 - 发送和接收数据。 [英] Form to form communication - send and receive data.

查看:96
本文介绍了形成通信的形式 - 发送和接收数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表单,一个名为IDE,另一个名为CodeEditor。

这是我在构造函数中的代码:



I have two form, form one called IDE and form two called CodeEditor.
This is my code in the constructor :

private CodeEditor FCodeEditor;
public IDE()
        {
InitializeComponent();
FCodeEditor = new CodeEditor(this);
}

//this is method to get string from form CodeEditor

string ILPcodes;
        public string ILPCodes(string codes)
        {
            ILPcodes = codes;
            return ILPcodes;
        }

//then i try to call method signalActiveTheLexer from form code editor to return the string to ILPcodes variable.

public void lex()
{
            FCodeEditor.signalActiveTheLexer();

            //Lexing
            adaptiveILPLexer(ILPcodes);
}





这是表格CodeEditor的构造函数:





This is constructor for form CodeEditor :

private IDE SendToIDE;
        public CodeEditor(IDE MainForm)
        {
            SendToIDE = MainForm;
        }

//this is the method that i wish can return the code from codeeditor control
public void signalActiveTheLexer()
        {
            SendToIDE.ILPCodes(CodeEditorControl.Text);
        }





问题我总是得到null结果?为什么?我用textbox1.text更改codeeditorcontrol,结果仍然为null。如果我使用这种技巧从表格到班级进行互动,结果总是成功,但表格形成我遇到问题



我尝试过:



i读过这篇文章,但我看不出如何解决我的问题..

试图了解委托,构造函数,属性。 。



在表单之间传递数据 [ ^ ]

推荐答案

您有以下方法:

You have the following method:
public string ILPCodes(string codes)
{
    ILPcodes = codes;
    return ILPcodes;
}



返回一个字符串。



但是当你在<$ c中调用它时$ c> signalActiveTheLexer


which returns a string.

However when you call it in signalActiveTheLexer

public void signalActiveTheLexer()
{
    SendToIDE.ILPCodes(CodeEditorControl.Text);
}



您没有捕获返回值,即使您这样做,该方法也不会返回任何内容。您应该按如下方式更改它:


you do not capture the return value, and even if you did, that method does not return anything. You should change it as follows:

public string signalActiveTheLexer()
{
    return SendToIDE.ILPCodes(CodeEditorControl.Text);
}


这篇关于形成通信的形式 - 发送和接收数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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