本文介绍了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).
这篇关于C#窗口表单文本框字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!