G
Guest
I am writing a Windows Forms application using Visual Studio.NET in C#. I am creating a control derived from TextBox that will need to invoke a block cursor (caret) during certain edit modes. The derived control is intended to contain numeric values; integers and floating point. I understand how to create and position a caret using CreateCaret() and SetCaretPos(), available in user32.dll.
The control's font may vary from instance to instance so I want to make the caret have the correct width and height. I can get the height of the font by using either the TextBox.FontHeight property or the Font.Height property. However, I have not found a way to get the width of a character so that I can size the caret width appropriately. Since the control can contain a decimal point and a minus sign I would really like to determine the width of any individual character so that the caret does not overlap adjacent characters.
How can I determine the width of a character at a given position in a TextBox?
Thanks,
Dave
The control's font may vary from instance to instance so I want to make the caret have the correct width and height. I can get the height of the font by using either the TextBox.FontHeight property or the Font.Height property. However, I have not found a way to get the width of a character so that I can size the caret width appropriately. Since the control can contain a decimal point and a minus sign I would really like to determine the width of any individual character so that the caret does not overlap adjacent characters.
How can I determine the width of a character at a given position in a TextBox?
Thanks,
Dave