簡體   English   中英

使用C#Windows Form以相同的形式將文本從一個文本框傳遞到另一個文本框

[英]Passing text from one textBox to another in a same form using C# Windows Form

我正在嘗試做一些非常簡單的事情(至少我確實這么認為)。 我有一個帶有Split Container的表單,每個部分(共兩個)都只有一個textBox ,想法是,我在textBox1上編寫文本時可以在textBox2上看到它。 我想出了如何將一些數據從一個框傳遞到另一個框,但是我不知道如何獲取textBox的值並將其傳遞到另一個textBox 我想再次提到2個文本框是一種形式,因此我認為這應該是一個非常簡單的任務。 這是我的代碼:

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //how to get the text from textBox1?
            textBox2.AppendText("I want to pass the text form textBox1");
        }
    }

而且,我正在使用Visual Studio 2010

是否簡單:

textBox2.Text = textBox1.Text;

 private void textBox1_TextChanged(object sender, EventArgs e)
        {                
            textBox2.Text = textBox1.Text;
        }

嘗試這個

 `private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //how to get the text from textBox1?
            textBox2 = textBox1.Text;
        }`

如果只想從textbox1中獲取文本,請使用以下命令:

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //how to get the text from textBox1?
            textBox2 = textBox1.Text;
        }

但是,如果要將文本從textbox1添加到textbox2,請使用以下命令:

private void textBox1_TextChanged(object sender, EventArgs e)      
{
            //how to get the text from textBox1?
            textBox2.AppendText(textbox1.text);
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM