Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm a newbie at this so bare with me. Trying this in VS 2k8 WPF

I'm trying to copy the user's input string from one text box to another. Below works fine when I do this:
C#
private void buttonChange_Click(object sender, RoutedEventArgs e)
 {


     string userInput = boxTop.Text;
     boxBottom.Text = userInput;


 }


Below doesn't work. I'm missing something very basic and would like some help understanding this.

C#
private void buttonChange_Click(object sender, RoutedEventArgs e)
  {

      string userInput = boxTop.Text;
      string userOutput = boxBottom.Text;
      userOutput = userInput;



  }
Posted
Comments
[no name] 11-Jul-13 15:41pm    
In the second snippet you are setting two string variables equal to each other, not setting anything in textbox text.
[no name] 11-Jul-13 16:02pm    
An easier way to do this is to simply
boxBottom.Text = boxTop.Text;
PR3 11-Jul-13 16:06pm    
I originally was trying to do an "If" statement and basically didn't get no error, warning, etc.

This was within the buttonChange_Click that didn't work.
string userOutput = boxBottom.Text;
if (boxTop.Text == "42")
{
userOutput = "Good.";
}
else
{
userOutput = "Bad.";
}
[no name] 11-Jul-13 16:13pm    
Yes and all you are doing is setting userOutput to be some value. You are not setting the textbox text to anything. You would need to boxBottom.Text = userOutput at some point.
PR3 11-Jul-13 16:26pm    
That was it. Thank you very much. Something very simple I was missing.

1 solution

C#
private void buttonChange_Click(object sender, RoutedEventArgs e)
       {

           string userInput = boxTop.Text;
           string userOutput = boxBottom.Text;
           // Values saved in variables know you can change as you have done in first step.
           boxTop.Text = userOutput;
           boxBottom.Text = userInput;

       }
 
Share this answer
 
Comments
Member 11536930 16-Apr-15 15:39pm    
why is VS telling me that the type or namespace of 'RoutedEventArgs' could not be found??
MuhammadUSman1 20-Apr-15 1:09am    
You should google it. It'll save our time.
https://www.google.com/search?q=type+or+namespace+of+%27RoutedEventArgs%27+could+not+be+found&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-beta&channel=sb

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