【问题标题】:how to get text box data from hidden form to current form? [duplicate]如何将文本框数据从隐藏表单获取到当前表单? [复制]
【发布时间】:2014-06-10 22:26:43
【问题描述】:

在我的应用程序中,我有多个表单 form1 到 form6,我通过隐藏和显示方法在表单之间切换,在表单 3 中,我有多个文本框和复选框,我需要获取这些文本框数据和复选框状态按钮点击事件上的form6文本框...

public partial class Form6 : Form
{

     Form3 _form3;
     Form4 _form4;
    public Form6()
    {
        InitializeComponent();
    }

    private void L_Click(object sender, EventArgs e)
    {

            _form3 = new Form3();

            string str1 = _form3.textBox1.Text;
            textBox21.Text = (str1 + Environment.NewLine).ToString();
            string str2 = _form3.textBox11.Text;
            textBox21.Text = (str2 + Environment.NewLine).ToString();

            int result1 = _form3.checkBox1.CheckState == CheckState.Checked ? 1 : 0;
            int result2 = _form3.checkBox11.CheckState == CheckState.Checked ? 1 : 0;
            int result3 = _form3.checkBox21.CheckState == CheckState.Checked ? 1 : 0;
            int result4 = _form3.checkBox31.CheckState == CheckState.Checked ? 1 : 0;
            int result5 = _form3.checkBox41.CheckState == CheckState.Checked ? 1 : 0;
            int result6 = _form3.checkBox51.CheckState == CheckState.Checked ? 1 : 0;
            int result7 = _form3.checkBox61.CheckState == CheckState.Checked ? 1 : 0;
            int result8 = _form3.checkBox71.CheckState == CheckState.Checked ? 1 : 0;
            int result9 = _form3.checkBox81.CheckState == CheckState.Checked ? 1 : 0;
            int result10 = _form3.checkBox91.CheckState == CheckState.Checked ? 1 : 0;

            textBox21.Text = (result1).ToString();
            textBox21.Text = (result2).ToString();
            textBox21.Text = (result3).ToString();
            textBox21.Text = (result4).ToString();
            textBox21.Text = (result5).ToString();
            textBox21.Text = (result6).ToString();
            textBox21.Text = (result7).ToString();
            textBox21.Text = (result8).ToString();
            textBox21.Text = (result9).ToString();
            textBox21.Text = (result10).ToString();
}

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    您的问题是您没有引用 Form3 的当前实例,而是创建一个新实例,试试:

        Form3 form3;
        public Form6(Form3 form3)
        {
            InitializeComponent();
            this.form3=form3;
        }
    
    
     private void L_Click(object sender, EventArgs e)
        {
           int result1 = form3.checkBox1.CheckState == CheckState.Checked ? 1 : 0;
           int result2 = form3.checkBox11.CheckState == CheckState.Checked ? 1 : 0;
           //...
           //...   
        }
    

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 2012-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 2014-06-26
      • 2016-05-18
      • 2023-02-11
      • 1970-01-01
      相关资源
      最近更新 更多