Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

GetPositionFromCharIndex(int index) in RichTextBox v.s. TextBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JamesDastard@gmail.com - 31 Jan 2007 07:12 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.