繁体   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