Click here to Skip to main content
15,881,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,

I am using two textbox, When I leave the first textbox using with the mouse (by clilcking on another textbox on the form) it is come out.

my quoestion: if the textbox is empty the cursor not come out. please help me
Thanks
Posted

1 solution

I assume you mean to ask how to set the focus back to textBox1 if the text is empty. To do this you need to handle the PreviewLostKeyboardFocus event. There you check if textbox is empty and if so set e.handled to true like this:-

XML
<TextBox Name="textBox1" PreviewLostKeyboardFocus="textBox1_PreviewLostKeyboardFocus" />



C#
private void textBox1_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                e.Handled = true;
            }
        }


Hope this helps
 
Share this answer
 
v2
Comments
gpasupathi 7-Sep-11 4:34am    
Dear sir, many thanks it is working fine. sorry for the poor english
Wayne Gaylard 7-Sep-11 4:37am    
My pleasure. The English is not a problem, I'm sure you speak better English than I speak your language.

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