如何以另一种形式访问文本框文本 [英] How to access textBox text in another form

查看:28
本文介绍了如何以另一种形式访问文本框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个表单:Form1、Form2

Form1 中,我有一个 textBox ,其中包含一些用户必须输入的数据.我需要用户在 Form1 的 textBox 中输入的 text.如何在 Form2 中访问它?

我使用了 property 但它不起作用,因为用户在运行时输入的文本值.任何机构可以帮助我吗?

I have 2 forms: Form1, Form2

In Form1 I have a textBox with some data that user have to enter. I need the text that the user entered in Form1's textBox. How can I access to that in Form2?

I used property but it did not work because the text value entered by user in run time. can any body help me?

推荐答案

为 form2 创建一个接受字符串的构造函数,并在调用 new form2 时将 form1.frm1Textbox.text 传递给构造函数,然后将其设置为 form2.frm2Textbox.text

Make a constructor for form2 that accept string and in calling new form2 pass form1.frm1Textbox.text to contructor then set it to form2.frm2Textbox.text

Form2 form = new Form2(frm1Textbox.text);

在form2构造函数中

in form2 constructor

public class Form2 : Form
{
    public Form2(string text)
    {
        frm2Textbox.Text = text; 
    }
}

这篇关于如何以另一种形式访问文本框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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