Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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

C#
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";
    }
}
Posted
Updated 26-Dec-11 11:36am
v2

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


Should do the job (discard textBox1_TextChanged: you don't need it for this task).
 
Share this answer
 
v2
Comments
Joel Whatley- 26-Dec-11 17:47pm    
The application is a calculator, just practicing some windows form stuff, the user has 0-9 buttons for each number and a textbox which displays the numbers. I need the textbox in there to display answers/numbers etc so I can't remove it I just need it to always display the string when it updates
CPallini 26-Dec-11 17:50pm    
I suggested you to remove the textbox1_TextChanged event handler, not the text box itself.
Joel Whatley- 26-Dec-11 17:55pm    
I don't understand :P (new to programming)
If I delete textBox1_TextChanged then it messes up the textbot
Joel Whatley- 26-Dec-11 18:29pm    
Oh i get it :D Thanks! helped so much
CPallini 26-Dec-11 18:40pm    
You are welcome.
Who needs a calculator with buttons?

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

—SA
 
Share this answer
 
Comments
Joel Whatley- 26-Dec-11 19:53pm    
I'm only practising :) New to this stuff

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900