View Single Post
Old Jul 1st, 2005, 9:50 AM   #1
nez
Programmer
 
nez's Avatar
 
Join Date: May 2005
Location: Plymouth UK
Posts: 34
Rep Power: 0 nez is on a distinguished road
Send a message via MSN to nez
Simple c# question

Hi all,
Im building my first small program in Visual C# 2005 express, you enter your name in a text box and press the ok button and it changes the value of a label so it shows "hello <name entered>", its all working fine, but i would like it to change the name of the labels when you press return in the text box but im not sure how to do it, any advise would be apreciated, thanks
Nez

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        string name;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "Hello";
            label3.Text = name; 
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            name = textBox1.Text;
        }
    }
}
n.b This is what i have so far, i tried using an if statement, but i couldnt quite get it right, im sure there must be some simple line or two i can put in the textbox1 section.
__________________
atariboy.wordpress.com
nez is offline   Reply With Quote