blinking cursor on custom control in c sharp .net

Posted on 2009-02-10
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.

Question by:thready
    LVL 22

    Expert Comment


    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
    Although I think it must be easier to use a textbox and validate the input according to your rules.

    LVL 1

    Author Comment

    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?

    LVL 22

    Accepted Solution

    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.
    LVL 1

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now