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

how to input numbers in to the second text box . 如何在第二个文本框中 输入数字 whenever I click the button it keeps appearing in the 1st textbox 每当我单击按钮时,它就会一直出现在第一个文本框中

My Code: 我的代码:

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";

        }
    }
}

Looking at your code I assume you have multiple buttons for each number and each button has its own Click event handler. 查看您的代码,我假设每个数字都有多个按钮,并且每个按钮都有自己的Click事件处理程序。 So it looks like you are changing both text boxes in each event handler 所以看起来您正在更改每个事件处理程序中的两个文本框

    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
    }

All you need to do is to change each Click event handler to change only text box 2. 您需要做的就是更改每个Click事件处理程序,以仅更改文本框2。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WinForm C#列表框,单击按钮,txt框。 项目总和 - WinForm C# list box ,click button ,txt box. sum of items 在C#中,如何在第一次单击后禁用一个按钮,然后在单击另一个按钮后再次启用它? - in c#, how can you disable a button after the 1st click, and enable it again after you click another button? 第一次单击后如何禁用按钮 - How to disable a button after 1st click 使用从文本框中读取名称保存文件。 C# - Saving files with name read from text box. C# WPF C#中的组合框第一个项目保持空白 - Combo Box 1st item is remained empty in WPF c# 每当我单击 C# 中的按钮时,如何将 Append 项添加到另一个 Window 中的列表框? - How Do I Append Items to a Listbox in Another Window Whenever I Click a Button in C#? C#winform第二次按钮点击时文本框如何变为空? - C# winform how textbox became null on button click second time? 有一个问题。我已经点击了第二个文本框,但它一直出现在两个文本框中。 当我点击它的文本框时,我希望号码弹出。 1 当时 - have a prob.I already click the second textbox but it keeps appearing in both. I WANT THE NUMBER TO POP WHEN I CLICK ITS TEXTBOX. 1 at the time 按钮文字未出现C# - Button text not appearing c# 当用户单击所有选定的文本时,如何创建按钮必须在 c# 中的富文本框的中心对齐 - How can I create a button when a user click all selected text must be align on the center of rich textbox in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM