[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


blinking cursor on custom control in c sharp .net

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

Question by:thready
  • 2
  • 2
LVL 22

Expert Comment

ID: 23605529

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.


Author Comment

ID: 23605979
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

pivar earned 2000 total points
ID: 23606094
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.

Author Closing Comment

ID: 31545299

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

873 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