简体   繁体   English

如何将文本框的文本从弹出窗口传递到主窗体?

[英]How do I pass the text of a textbox from a pop-up window to the main form?

My program is basically reading barcodes, but I want to allow users to enter barcode manually, so I created a pop up window for that. 我的程序基本上是读取条形码,但是我希望允许用户手动输入条形码,因此我为此创建了一个弹出窗口。 After entering the barcode, I want the pop up window to disappear and send data to the main form when ENTER is hit, but I have no clue how this data can be passed to the main form. 输入条形码后,我希望弹出窗口消失,并在按ENTER键时将数据发送到主表单,但是我不知道如何将这些数据传递到主表单。

Ok, this is pretty straightforward, I'll show you with an example. 好的,这很简单,我将举一个例子。 You have two forms: Form1 mainForm and Form 2 subForm. 您有两种形式:Form1 mainForm和Form 2 subForm。

mainForm calls subForm as follows: mainForm调用subForm如下:

using (Form2 subForm = new Form2())
{
    if (subForm.ShowDialog() == DialogResult.OK)
    {
        string my_text = subForm.TextToReturn;
        // Do stuff with my_text
    }
}    

In SubForm you will have something like this declared in the class scope: 在SubForm中,您将在类范围中声明以下内容:

public string TextToReturn;

private void button1_Click(object sender, EventArgs e)
{
    TextToReturn = text_box.Text; 
    this.DialogResult = DialogResult.OK;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从itextsharp注解弹出一个窗口显示图片和文字 - pop-up a window from itextsharp annotation to display images and text 如何使用新页面作为弹出源创建弹出窗口? - How can I create a pop-up window using a new page as the pop-up source? 如何使用gridview(一个新的弹出窗口)中的超链接字段链接回我的主页 - How do I use the hyperlink field in gridview, a new pop-up, to link back to my main page WPF:如何将线程中的文本框文本传递到主窗口? - WPF: How can I pass the text of textbox in a thread to the main window? 如何关闭弹出窗口并将视图模型返回到上一个视图? - How do I close a pop-up window & return a view model to the previous view? 如何使用相同的 xaml 文件在弹出窗口中显示不同的名称? - How do I display different names in the pop-up window by using the same xaml file? 如何在WPF中从弹出对话框窗口导航到另一个页面我未使用MVVM - How to navigate from a pop-up dialog window to another page in wpf i'm not using MVVM 如何打开一个弹出窗口 - How to open a pop-up window 如何设置弹出窗口的焦点? - how to set focus for the pop-up window? 当人们选择器从浏览弹出窗口将值返回到主表单时,我需要触发jquery - i need jquery to fire when people picker returns the value to the main form from the browse pop up window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM