Solved

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

Posted on 2007-12-04
11
278 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

12 Experts available now in Live!

Get 1:1 Help Now