selection location in RichTextBox

hi again experts,
i have a RichTextBox in which the user designs dumb terminal screens.  i've fixed the size so that it only allows 80 chars per line and a total of 24 lines.  after the user gets the screen (rtb) looking like they want it, i need my code to translate the screen into a file that desribes the layout of the screen.  in order to do this, i plan to scan the text by selecting each character one by one.  if i could detect a change in y-coordinate of the selected text, i could tell when a new line will need to be described.  any idea on how to do this?


Who is Participating?
Closed, 100 points refunded.
Site Admin
In a RTB with multiple lines set at 80 characters you could look for \r\n to determine when a newline is entered.  Of course you will have to set the RTB to do hardreturns to ensure that the \r\n will be there...
ryeandiAuthor Commented:
how do you set the rtb to do hardreturns?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

There is a wordwrap property that you will want to set to false.  Also, the RTB does not use \r\n for the return rather it uses \n...

Also, if you have preprogramed in 24 lines at 80 characters you may be able to use the lines property on the RTB...
ryeandiAuthor Commented:
thanks nipnfriar__tuck,
but what i'm really looking for is a way to know if the y-pos changed when scanning like in my original post.  i've been trying to use the method you describe but have found that too many variables come into play.  one problem is that i've sized my rtb to 80 characters using a fixed sized font.  turning off wordwrap causes the lines to expand.  if i use a word wrap and my method for controling the number of lines, all i need is to scan the rtb looking for change in y-pos and i'll know which line i'm on.  
ryeandiAuthor Commented:
actually i just figured it out myself.

Point pt;
int yCord = -1;
for(int i = 0; i < rtb.Text.Length; i++)
  pt = rtb.GetPositionFromCharIndex(i);
  if(yCord != pt.Y)
    yCord = pt.Y;
    MessageBox.Show("Character: " + rtb.Text[i] + " starts a new line");

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.