?
Solved

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

Posted on 2007-12-04
11
Medium Priority
?
302 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 1000 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

Industry Leaders: 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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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

770 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