【问题标题】:C# TextBox Input from Form1 to Form Name Output in Form2? [closed]C# TextBox 从 Form1 输入到 Form2 中的表单名称输出? [关闭]
【发布时间】:2021-08-08 13:20:19
【问题描述】:

我需要有关将文本框的输入转换为 FormName(FormText) 形式的代码的帮助。请帮助

【问题讨论】:

    标签: c# input output


    【解决方案1】:

    如前所述,这个网站上有很多例子,这里是一个。

    using System;
    using System.Windows.Forms;
    
    namespace PassingDataBetweenForms
    {
        public partial class Form2 : Form
        {
            private readonly string _input;
            public Form2()
            {
                InitializeComponent();
            }
            public Form2(string input)
            {
                InitializeComponent();
    
                _input = input;
                Shown += OnShown;
                
            }
    
            private void OnShown(object sender, EventArgs e)
            {
                textBox1.Text = _input;
            }
        }
    }
    

    表格1

    private void button1_Click(object sender, EventArgs e)
    {
        var f = new Form2(textBox1.Text);
        f.ShowDialog();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      相关资源
      最近更新 更多