Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
Is there any boolean function that returns whether a TextBox has the input cursor in it or not?

it should look like this:

C#
if(textBox1.HasCursor)
{
    //do something

}
Posted
Updated 28-Sep-11 7:55am
v2

You must use "Enter" and "Leave" Events of your textbox :)

C#
private void textBox1_Enter(object sender, EventArgs e)
{
    //do something
}
 
Share this answer
 
Comments
Simon Bang Terkildsen 28-Sep-11 14:35pm    
so I take it you're the one who does not like mine and varunjeeri's answer. varunjeeri's answer is the exact same as yours. My answer is the exact thing the OP is asking for.
When you down vote have the balls to leave a comment stating why.
George_Rasmi 28-Sep-11 16:10pm    
it worked Thanks :)
hzawary 28-Sep-11 16:15pm    
you're very welcome
Test for focus, if the textbox has focus then the input cursor is active. E.g. in winforms
C#
if(textBox1.Focused)
 
Share this answer
 
Comments
hzawary 28-Sep-11 15:52pm    
US answer is better than answer Denmark;)
Simon Bang Terkildsen 28-Sep-11 17:00pm    
damn you're obnoxious
hzawary 28-Sep-11 17:33pm    
Go to grasp with your arms;)
George_Rasmi 28-Sep-11 15:52pm    
this method is not working :(
it always returns false even if the cursor was in the textbox
Simon Bang Terkildsen 28-Sep-11 16:59pm    
Then you're doing something wrong
Try adding onfocus event to the textbox, so that whenever the textbox has cursor in it, the event occurs.
 
Share this answer
 
Comments
George_Rasmi 28-Sep-11 16:10pm    
it worked Thanks :)

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