簡體   English   中英

C#如何在第二個文本框中輸入數字。 每當我單擊按鈕時,它就會一直出現在第一個文本框中

[英]C# how to input numbers in to the second text box. whenever I click the button it keeps appearing in the 1st textbox

如何在第二個文本框中 輸入數字 每當我單擊按鈕時,它就會一直出現在第一個文本框中

我的代碼:

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        private void tbox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void one_Click(object sender, EventArgs e)
        {

            tbox1.Text = tbox1.Text + "1 a";
            tbox2.Text = tbox2.Text + "A";


        }

        private void two_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "2 b";
            tbox2.Text = tbox2.Text + "B";

        }

        private void tbox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void three_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "3 c";
            tbox2.Text = tbox2.Text + "C";
        }

        private void four_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "4 d";
            tbox2.Text = tbox2.Text + "D";
        }

        private void five_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "5 e";
            tbox2.Text = tbox2.Text + "E";
        }

        private void six_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "6 f";
            tbox2.Text = tbox2.Text + "F";
        }

        private void seven_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "7 g";
            tbox2.Text = tbox2.Text + "G";
        }

        private void eight_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "8 h";
            tbox2.Text = tbox2.Text + "H";
        }

        private void nine_Click(object sender, EventArgs e)
        {
            tbox1.Text = tbox1.Text + "9 i";
            tbox2.Text = tbox2.Text + "I";
        }

        private void zero_Click(object sender, EventArgs e)
        {          
                tbox1.Text = tbox1.Text + "0 j";
                tbox2.Text = tbox2.Text + "J";

        }
    }
}

查看您的代碼,我假設每個數字都有多個按鈕,並且每個按鈕都有自己的Click事件處理程序。 所以看起來您正在更改每個事件處理程序中的兩個文本框

    private void eight_Click(object sender, EventArgs e)
    {
        tbox1.Text = tbox1.Text + "8 h"; // changing text box 1
        tbox2.Text = tbox2.Text + "H"; // changing text box 2
    }

您需要做的就是更改每個Click事件處理程序,以僅更改文本框2。

暫無
暫無

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

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