Click here to Skip to main content
15,891,726 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Dear all,

I do not understand the code below. Would you like to explain me about it?
Here is the code:
private void txtFirstName_Enter(object sender, EventArgs e)
        {
            TextBox txt = (TextBox)sender;
            string t = txt.Name.Substring(3, txt.Name.Length - 3);
            if (txt.Text.ToLower() == t.ToLower())
            {
                txt.ForeColor = System.Drawing.Color.Black;
                txt.Text = "";
            }
        }

        private void txtFirstName_leave(object sender, EventArgs e)
        {
            TextBox txt = (TextBox)sender;
            string t = txt.Name.Substring(3, txt.Name.Length - 3);
            if (txt.Text.ToLower() == t.ToLower() || txt.Text == "")
            {
                txt.ForeColor = System.Drawing.Color.Silver;
                txt.Text = t;

            }
            else
            {
                txt.ForeColor = System.Drawing.Color.Black;
            }
        }


Thank you so much.
Posted
Comments
Suraj S Koneri 16-Jan-12 21:36pm    
you didnot code this?
phanny 2011 16-Jan-12 21:37pm    
what do you mean?
AspDotNetDev 16-Jan-12 21:37pm    
There's a lot that could be explained. What specifically don't you understand about the code?
phanny 2011 16-Jan-12 21:39pm    
The line
string t = txt.Name.Substring(3, txt.Name.Length - 3);
I don't understand.
Thanks
AspDotNetDev 16-Jan-12 21:57pm    
Is this homework you have been assigned? If that line isn't obvious to you, I suggest you either figure out how to use the debugger or figure out how to show a message using MessageBox.Show. Google will be your friend for either of those tasks.

1 solution

string t = txt.Name.Substring(3, txt.Name.Length - 3);


Not difficult to understand if you read the documentation
http://msdn.microsoft.com/en-us/library/aka44szs.aspx[^]
 
Share this answer
 

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