[英]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.