Hi, I want to declare a string value in a WPF application.
Example:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox1.Text == "Name")
{
label1.Content = "This is " + textBox1.Text;
}
}
If the user enter NAME/ name/ Name the if condition should apply and give the corresponding output
ie. label1 should display This is Name/ NAME/etc.
Loading
Adarsh BalachandranPosted Feb 20, 2014, 11:40 PM
if (textBox1.Text == "Name")
{
label1.Content = "This is " + textBox1.Text;
}
else
{
label1.Content = "This is not my " + textBox1.Text;
}
If I enter name in the text box, it will satisfy only the else condition and will display This is not my name. Instead of that it has to display This is my name. That is the first if condition statement should work for names, Name, NAME, nAME, etc.
theLizardPosted Feb 20, 2014, 4:01 PM
If TextBox1 should always be upper case or lower case for that matter, then all you need to do is
TextBox1.Text = textBox1.Text.ToUpper();
OR simply
label1.Content = "This is " + textBox1.Text.ToUpper();
Sanjeeb LenkaPosted Feb 20, 2014, 3:59 AM
if (textBox1.Text.ToUpper() == "NAME")
{
label1.Content = "This is " + textBox1.Text;
}