473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

RichTextBox.GetLineFromCharIndex Discrepancy

Can someone please explain why I get a different result when using the
GetLineFromCharIndex method on the last char in the Text property and the
Lines.Length property?

MainForm_gedcomTextBox is a RichTextBox.

For example this code:

private void End_menuItem_Click(object sender, System.EventArgs e)
{
int lastLine = MainForm_gedcomTextBox.GetLineFromCharIndex
(MainForm_gedcomTextBox.Text.Length -1);
string one =
MainForm_gedcomTextBox.Text.Substring(MainForm_ged comTextBox.Text.Length-6);
string two =
MainForm_gedcomTextBox.Lines[MainForm_gedcomTextBox.Lines.Length-1];
MainForm_gedcomTextBox.SelectLine(MainForm_gedcomT extBox.Lines.Length-1);
}

produced:
lastLine = 144352
one = "0 TRLR"
two = "0 TRLR"
MainForm_gedcomTextBox.Lines.Length = 144082

--
Arlyn_L
Nov 16 '05 #1
1 2837
Hi Arlyn_L,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that the GetLineFromCharIndex returns
different line number of the last character from the Lines.Length-1. If
there is any misunderstanding, please feel free to let me know.

Based on the document, we can see that GetLineFromCharIndex returns the
physical line number where the indexed character is located within the
control. For example, if a portion of the first logical line of text in the
control wraps to the next line, the GetLineFromCharIndex method returns 1
if the character at the specified character index has wrapped to the second
physical line. If WordWrap is set to false, no portion of the line wraps to
the next, and the method returns 0 for the specified character index.

However, the Lines property considers lines as logical lines where each
line ends with a carrige return. So there will be difference between two
return values of line number, while the strings are the same.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DMD | last post by:
How do I determine the column associated with the current edit location within a RichTextBox? The following code allow me to determine the current line txtLineNumber.Text =...
6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
3
by: GSX | last post by:
I've been reading and searching (and searching and reading) for far too many hours. I'm rather new - so I apologize if this is an over asked question... I'm working on a small text editor as a...
0
by: Sakharam Phapale | last post by:
Hi All, How to get the starting and end character position of the given line no in RichTextBox? I have written following code but it takes more time. Is there any RichTextBox function or API...
2
by: Mark Raishbrook | last post by:
....without resorting to SendMessage. Imagine, for example, I have a small RTB whose text has wrapped as follows: "This is a small test to see if I can get" "both of these lines". ...
1
by: Udi | last post by:
Hi, I have derived my ConsoleTextBox from RichTextBox. I'm trying to implement a console-like text box with history capabilities. My problem is that when I'm trying to append a command, I can't...
0
by: Udi | last post by:
Hi, I have derived my ConsoleTextBox from RichTextBox. I'm trying to implement a console-like text box with history capabilities. My problem is that when I'm trying to append a command, I can't...
2
by: Don Gollahon | last post by:
..NET 1.1 How do I get the line # the cursor is currently in in a RichTextBox? Cursor x, y coordinates in the component would be nice. Thanks. -- Don Gollahon
2
by: macky caliston | last post by:
Hi, Im having problems with the value being returned by the richtextbox.GetLineFromCharIndex method. Its returning a value that is more than the richtextbox.Lines.Length. Im trying to print...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.