C#窗口表单文本框字符串 [英] C# Window form textbox string

查看:129
本文介绍了C#窗口表单文本框字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码将字符串number1写入文本框,并添加一个按钮(button2),将"1"添加到字符串number1中,这样它就会出现在文本框中,但是一旦i',文本框仅显示其中的文本按下了字母或Enter之类的按钮,是否知道如何使其始终显示字符串?

询问我是否不够清晰

I have this code to write the string number1 into the textbox and a button (button2) to add "1" to the string number1 so it would appear in the textbox, but the textbox only shows the text inside it once i''ve pressed a button on it like a letter or Enter, any idea how to make it always show the string ?

ask questions if im not clear enough

private void textBox1_TextChanged(object sender, EventArgs e)
{
        textBox1.Text = number1.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
    if(num1)
    {
        number1 = number1 + "1";
    }
    if (!num1)
    {
        number2 = number2 + "1";
    }
}

推荐答案

private void button2_Click(object sender, EventArgs e)
{
  if(num1)
  {
    number1 = number1 + "1";
    textBox1.Text = number1;   
  }
  else
  {
    number2 = number2 + "1";
    // textBox2.Text = number2;
  }
}



应该完成这项工作(放弃textBox1_TextChanged:您不需要此任务).



Should do the job (discard textBox1_TextChanged: you don''t need it for this task).


谁需要带按钮的计算器?

要查看真正有用的计算器应该如何工作,请看一下我的 在线计算器 .

—SA
Who needs a calculator with buttons?

To see how a really useful calculator should work, take a look at my On-line Calculator.

—SA


这篇关于C#窗口表单文本框字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆