Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows string Text form
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";
            }
        }
Posted 26-Dec-11 12:21pm
Edited 26-Dec-11 12:36pm
CPallini326.1K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
v2
Comments
Joel Whatley- at 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 at 26-Dec-11 17:50pm
   
I suggested you to remove the textbox1_TextChanged event handler, not the text box itself.
Joel Whatley- at 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- at 26-Dec-11 18:29pm
   
Oh i get it :D Thanks! helped so much
CPallini at 26-Dec-11 18:40pm
   
You are welcome.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Who needs a calculator with buttons?
 
To see how a really useful calculator should work, take a look at my On-line Calculator.
 
—SA
  Permalink  
Comments
Joel Whatley- at 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)

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 26 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100