views:

566

answers:

1

I'm developing a custom control, which most resembles a text area. I am drawing text, which works correctly, and accepting input which also works.. But I (the user) am left guessing where the caret is while I type, since I'm doing everything manually. How do I draw a blinking caret to show where I am currently typing? Is there a standard way to do this?

+1  A: 

I think that, annoyingly, there is no managed API for Carets. You must, therefore, either PInvoke to the Win32 functions for carets, or, implement that functionality yourself (i.e. painting and hiding a blinking caret, when and only when your control has the input focus).

See http://stackoverflow.com/questions/609927/custom-caret-for-winforms-textbox for example.

ChrisW
I really hate resorting to win32 functions, so I guess I am stuck manually drawing the caret. Still secretly hoping someone will come along saying "oh no, just use this magical function" though ;-)
Ko9
I wish. FWIW my algorithm to show the caret is to paint a narrow rectangle; and to hide the caret, I then repaint that rectangle using the background colour, and also repaint the word (the word's background rectangle, and its foreground text).
ChrisW