?
Solved

selection location in RichTextBox

Posted on 2004-08-17
7
Medium Priority
?
276 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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

800 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