We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


blinking cursor on custom control in c sharp .net

thready asked
Medium Priority
Last Modified: 2013-12-17
Hi Experts,

I'd like to create my own edit control which shows the date in the form YYYY-MM-DD.  This control will validate the date if it's specified in its entirety, but it will also allow the user to only specify the year or just the year and month if they want.

My question is, I could subclass the edit control directly, but if I was creating my own UserControl, then how would I show a blinking cursor?  (how do they do it in the actual edit control)?  Do they create a thread to set paint events to draw it and then remove it - or a timer?

Any suggestions on creating this control would be appreciated.

Watch Question


The blinking cursor is called a caret and you can create it via Win32 API. Haven't tried it myself though. Here's a link to p/invoke http://www.pinvoke.net/default.aspx/user32/CreateCaret.html.
Although I think it must be easier to use a textbox and validate the input according to your rules.



Hi Peter,

Thanks for your response.  If I go for the textbox with the validating input, is there a way to do something like Facebook's login (where they place a grayed out 'login' in the login textbox and a grayed out 'password' in the password box)?

i.e., is there a way to have 2 fonts at a time in the textbox so that I can display YYYY-MM-DD grayed and type as much of the date as I need (leaving the grayed background there as long as I don't type more and more of the date?

In that case you have to implement your own OnPaint for your TextBox. The RicheditBox would allow you to have different fonts, colors etc, but may in this case be awkward to work with.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.