Clipping the caret in a C# program

Posted by Bob Sammers on Stack Overflow See other posts from Stack Overflow or by Bob Sammers
Published on 2010-05-07T16:26:40Z Indexed on 2010/05/07 19:18 UTC
Read the original article Hit count: 335

Filed under:
|
|
|

I'm creating a WinForms control in C# (using VS2008, .net 3.5) which allows text input. I've imported the necessary Win32 API functions from User32.dll for displaying the normal Windows caret and these are all working fine, but it's not displaying exactly how I'd like it.

Text is displayed on the control with a blank border and I use Graphics.SetClip() to leave this margin clear. I want the caret to be clipped to the same region, but since I don't paint it and there's no obvious API function to set a clipping region, I can't see any way of doing this. Have I missed anything obvious?

The caret is clipped inside the control in which it is drawn. I'm therefore aware that one solution could be to place the text in a separate sub-control with no border. However, if there's a simpler way than redesigning this part of the control, I'd like to look for that first.

Thanks in advance for any help!

© Stack Overflow or respective owner

Related posts about .NET

Related posts about win32