Solved

selection location in RichTextBox

Posted on 2004-08-17
7
269 Views
Last Modified: 2010-04-15
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?

thanks,

rye
0
Comment
Question by:ryeandi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 11822763
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...
0
 
LVL 1

Author Comment

by:ryeandi
ID: 11822812
how do you set the rtb to do hardreturns?
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 11823035
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...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:ryeandi
ID: 11823308
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.  
0
 
LVL 1

Author Comment

by:ryeandi
ID: 11823611
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");
  }
}

thanks.  
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11859724
Closed, 100 points refunded.
Netminder
Site Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RegEx with optional part 4 52
How to Generate a Method from a keyboard shortcut in Visual Studio? 2 34
C# Linq Select From List 3 43
Securing WEBAPI on Azure 2 21
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question