Dear all,
I found the GetPositionFromCharIndex(int index) is a little different
from that in TextBox. And I have a question.
Explain:
If the length of TextBox & RichTextBox are both 2.
textBox1.GetPositionFromCharIndex(2) -> invalid, return 0.
textBox1.GetPositionFromCharIndex(1) -> valid, return the
left bound position of the last
richTextBox1.GetPositionFromCharIndex(2) -> valid, return the right
bound position of the last character.
However, because each character are not in the same width, I cannot
count the bound manually.
Thus, does anybody know how could I get the "right bound position" of
the last character in "TextBox" but not "RichTextBox" ?
Wait for your help.
Sincerely,
James JAN <JamesDastard@gmail.com>
ClayB - 01 Feb 2007 11:01 GMT
Maybe code like this will give you what you want:
using (Graphics g = textBox1.CreateGraphics())
{
int len = textBox1.TextLength;
int rightEdge = textBox1.GetPositionFromCharIndex(len - 1).X
+ (int)
g.MeasureString(textBox1.Text.Substring(len - 1, 1),
textBox1.Font).Width;
}
===============================
Clay Burch
Syncfusion, Inc.