Solved

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

Posted on 2007-12-04
11
290 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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