在C#中返回Windows窗体的结果 [英] Return result between Windows Forms in C#

查看:94
本文介绍了在C#中返回Windows窗体的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Windows窗体(MyApp的,发电机),我需要从MyApp的调用发电机

 表格创=新生成器();
gen.Show();
字符串结果= gen.IDontKnowWhatToDoHere();
 

我Generator.cs形式有三个文本框和一个按钮确定,所以当用户键入三个文本框一些文本并单击确定我想要得到的输入这三个文本框的文本。

你有什么想法我如何能做到这一点。

感谢。

解决方案

 类生成器:表格
{
    公共字符串文本1 {获得;私定; }

    无效ok_Click(对象发件人,EventArgs)
    {
        this.Text1 = txt1.Text;
        ...
        this.Close();
    }
}

表单创=新生成器();
gen.ShowDialog();
字符串的text1 = gen.Text1;
...
 


 类TextInfo中
{
    公共字符串文本1 {获得;组; }
    ...
}

类生成器:表格
{
    公共TextInfo中TextInfo中{获得;私定; }

    公共发生器(TextInfo中的信息)
    {
        this.TextInfo =信息;
    }

    无效ok_Click(对象发件人,EventArgs)
    {
        this.TextInfo.Text1 = txt1.Text;
        ...
        this.Close();
    }
}

TextInfo中信息=新TextInfo中();
表单创=新的发电机组(信息);
gen.ShowDialog();
字符串的text1 = info.Text1;
 

I have two Windows Forms (MyApp, Generator), and I need to call Generator from MyApp

Form gen = new Generator();
gen.Show();
string result = gen.IDontKnowWhatToDoHere();

My Generator.cs Form has three TextBox and a Button Ok, so when the user type some text in the three TextBoxes an click Ok I want to get the the Text typed in those three TextBoxes.

Do you have any ideas how I can achieve this.

Thanks.

解决方案

class Generator : Form
{
    public string Text1 { get; private set; }

    void ok_Click (object sender, EventArgs)
    {
        this.Text1 = txt1.Text;
        ...
        this.Close();
    }
}

Form gen = new Generator();
gen.ShowDialog();
string text1 = gen.Text1;
...


class TextInfo
{
    public string Text1 { get; set; }
    ...
}

class Generator : Form
{
    public TextInfo Textinfo { get; private set; }

    public Generator(TextInfo info)
    {
        this.TextInfo = info;
    }

    void ok_Click (object sender, EventArgs)
    {
        this.TextInfo.Text1 = txt1.Text;
        ...
        this.Close();
    }
}

TextInfo info = new TextInfo();
Form gen = new Generator(info);
gen.ShowDialog();
string text1 = info.Text1;

这篇关于在C#中返回Windows窗体的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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