Solved

selection location in RichTextBox

Posted on 2004-08-17
7
242 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now