473,796 Members | 2,541 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 2870
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
1808
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
29232
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
1521
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
9685
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
10018
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...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
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
5446
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
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.