Solved

How do I stop the cursor jumping on space or punctuation when highlighting text in a RichTextBox?

Posted on 2007-12-04
11
299 Views
Last Modified: 2013-12-16
I am writing a text re-formatting program based on the character type (e.g. number, letter etc) of the exact characters selected. It needs fine control of the highlight text. Using a RichTextbox the highlight jumps to the next word given spaces or punctuation. I need it to hightlight (and select) only the columns that I have selected with the cursor and stop being 'helpful'.
I note the behaviour appears correct (for me) in TextBox.
0
Comment
Question by:markbeasley
[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
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20402908
>>I need it to hightlight (and select) only the columns

I don't understand what you mean by "columns"?  

>>Using a RichTextbox the highlight jumps to the next word given spaces or punctuation

What do you mean by this?

Bob
0
 

Author Comment

by:markbeasley
ID: 20409690
Sorry that it was not clear.
We are re-formatting data files and filtering data on the basis of a particular character type such as number, space, letter etc being in a certain column position in the data file. For example, I might want to hghlight the following string
CMNT,
Out of the complete line:
CMNT,,,PROJECT...1234
As soon as the cursor gets to the "." in column position 5 the highlight jumps to column postion 7 i.e. the begining og the next word "PROJECT"
Hope this helps!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20411447
>>As soon as the cursor gets to the "." in column position 5 the highlight jumps
Can you give me some coding insight into your processing steps, because the words aren't cutting it?

Bob
0
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 

Author Comment

by:markbeasley
ID: 20412830
Hi Bob,
The difficulty is that it is the default behaviour of the RichTextBox. Put it another way, if you copy this data snippet into WordPad and try highlighting "CMNT." on he first line you will find the highlight will jump to the next word.
If you use NotePad then you are able to highlight the exact substring. It is the NotePad behaviour I am after, Note that TextBox behaves like NotePad, RichTextBox behaves like Wordpad.
Thankyou for your patience!

CMNT...PROJECT...XXX16
CMNT...AREA......AREA 3D
CMNT...SURVEY....3D 1994 (RE-MIGRATION)
CMNT...PROCESSED.SPECIAL IN-HOUSE PROCESSING GROUP
CMNT...          (GLASGOW)
CMNT...
CMNT...FORMAT(1) SPNT CARD
CMNT     >3DCDP> > 3D SP <>X-COORD<> Y-COORD <    >LINE<
CMNT...
CMNT...FORMAT(2) VELF CARD
CMNT     >3DCDP>    > T1 X V1 X T2 X V2 X T3 X V3 X T4 X V4 X T5 X V5 <
CMNT...
CMNT...THE PROCESSING GRID
CMNT     X1: 380642.40   Y1: 5851119.10   LINE:    1   SHOTPOINT:    1
CMNT     X2: 393796.67   Y2: 5867027.63   LINE:    1   SHOTPOINT: 1549
CMNT     X3: 362057.79   Y3: 5866486.13   LINE:  690   SHOTPOINT:    1
CMNT     PRIMARY PROFILE CELL SIZE.......13.335 M
CMNT     SECONDARY PROFILE CELL SIZE.....35.0 m

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20412924
Hmmm, I have:

Windows XP Professional SP2
Visual Studio 2005 Professional SP1

I tried to double click CMNT on the first line, and it worked.  I tried to highlight CMNT on the first line, and it worked.

Bob
0
 

Author Comment

by:markbeasley
ID: 20419058
Hi Bob,
No double clicking. Lets say you want to copy the string "CMNT. "- try and do this is Wordpad and as soon as the cursor reachs the ". "selection will jump to just before the "P"
Another example,
Open Wordpad and type My name is Bob
try copying the substring "My n" - again you will find the selection will try and be helpful and the word "name" will get selected as well.
To re-cap, when dealing with data this behaviour is undesirable and I want to switch it off in Richtextbox.

Mark

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20419561
I didn't mean that I was only double-clicking, I meant that I tried everything that I could think of to highlight CMNT (including double-clicking), and it worked as expected.  I even opened WordPad, and tried the same processes, and it also worked as expected.

There aren't any properties to control this behavior with the RichTextBox, so you need to look elsewhere for a possible solution.

Bob
0
 

Author Comment

by:markbeasley
ID: 20420127
The property that controls the behaiour is AutoWordSelection

There is a known bug that setting this to false has no affect. MicroSoft has it marked as "closed wont fix" for details see:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=115441
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20420308
Ok, so I missed that property (d'oh) :(

Changing that property value doesn't affect how the text is selected with my RichTextBox, I can still select CMNT without it extending the selection to include the '...'.

Bob
0
 

Author Comment

by:markbeasley
ID: 20420445
The key is selecting CMNT.    - The "." is vital, this triggers the AutoWordSelection

See http://www.msdner.com/dev-archive/128/2-8-1286449.shtm
for a solution to the problem.

Thanks for your help

Mark
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 20420531
Mark,

That is an interesting solution, but it is also interesting that I don't need anything like that for my simple RichTextBox to work.

Bob
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

689 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