Hi everyone,
I'm writing a custom TextBox that inherits from UserControl. I can't
use a standard TextBox, or inherit from it or TextBoxBase, as it needs
to support proper transparency, meaning both the background needs to
be transparent, and the foreground back colour (I'm finding that if I
set the background to transparent, and the foreground to black, text
is being rendered as black on white, which rather does away with the
transparency)
I need to draw,( in the OnPaint method) a caret at the correct
position, but can't really get it to work. Have tried computing the
position using graphics.MeasureCharacterRanges, but without luck
any help or tips would be appreciated
thanks in advance
rachel
Bob Powell [MVP] - 10 Nov 2007 22:11 GMT
Win32 has a Caret API that can be used to "correctly" position the caret in
the control.
Here are the DLL imports you can use...
[DllImport("user32.dll")]
public static extern int CreateCaret(IntPtr hwnd, IntPtr hbm, int cx, int
cy);
[DllImport("user32.dll")]
public static extern int DestroyCaret();
[DllImport("user32.dll")]
public static extern int SetCaretPos(int x, int y);
[DllImport("user32.dll")]
public static extern int ShowCaret(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern int HideCaret(IntPtr hwnd);
You still have to determine the text positions which you can do using
MeasureCharacterRanges.

Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
> Hi everyone,
>
[quoted text clipped - 15 lines]
>
> rachel