473,785 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RichTextBox.Get LineFromCharInd ex Discrepancy

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

MainForm_gedcom TextBox is a RichTextBox.

For example this code:

private void End_menuItem_Cl ick(object sender, System.EventArg s e)
{
int lastLine = MainForm_gedcom TextBox.GetLine FromCharIndex
(MainForm_gedco mTextBox.Text.L ength -1);
string one =
MainForm_gedcom TextBox.Text.Su bstring(MainFor m_gedcomTextBox .Text.Length-6);
string two =
MainForm_gedcom TextBox.Lines[MainForm_gedcom TextBox.Lines.L ength-1];
MainForm_gedcom TextBox.SelectL ine(MainForm_ge dcomTextBox.Lin es.Length-1);
}

produced:
lastLine = 144352
one = "0 TRLR"
two = "0 TRLR"
MainForm_gedcom TextBox.Lines.L ength = 144082

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

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

Based on the document, we can see that GetLineFromChar Index 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 GetLineFromChar Index 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
1807
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 = FormatNumber(RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart())+1,0 How do I determine the column location within the line? I must be missing something obvious, any help would be appreciated
6
29231
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 scroll is with ScrollToCaret(). But I don't know how to set the "caret" to a particular line. Any suggestions? -Rachel
3
9173
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 learning project using the RichTextBox control. I wish to display the current line and total line count on the status bar, and also the cursor position on the current line. I have found the current line by using...
0
1520
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 function which gives that? Private Sub SetLineStartEndPosition(ByVal myRichTextBox as RichTextBox, ByVal LineNo As Integer, ByRef StartPosition As Integer, ByRef EndPosition As Integer)
2
1598
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". GetLineFromCharIndex(RTB.TextLength) returns 1, telling me there are two lines in there. Using the Lines property to retrieve them will fail, however. As the line has soft-wrapped (i.e. the user has not hit Enter after "get"),
1
3411
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 place the cursor at the end of the text. ### See SetCmdLn() method: #### protected override bool IsInputKey(Keys keyData)
0
1588
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 place the cursor at the end of the text. ### See code below - problem in SetCmdLn() #### My questions are:
2
2916
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
4195
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 selected lines of text from a richtextbox control. Here is my sample code: The lines of text in the richtextbox control is 3283.
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.