Click here to Skip to main content
15,886,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to highlight the complete line in richTextbox
Note : If the textlength is small then also complete line should be highlighted.
And without any text is it possible to highlight the richTextBox line.
Please give me the solution if its possible.
Thanks so much!
Posted
Comments
Sergey Alexandrovich Kryukov 9-Mar-11 20:04pm    
WPF or Forms or what? What is highlight? Is is select or something else?
--SA

Do you mean selection?
Basically, you need to calculate starting position and length, (for example, of line by finding line delimiters) and assign the properties SelectionStart and SelectionLength appropriately.

There is also a way to find out line position by its index in the file. For WPF, you need to use the class System.Windows.Documents.TextPointer, for System.Windows.Forms.RichTextBox, use GetLineFromCharIndex and GetPositionFromCharIndex.

I can reach for further detail only if you try to implement it and ask a follow-up question if you have any problems. Also, you need to answer my questions and explain what you have on input (which line? line where the caret is, line by index or what?).

Speaking of the "highlight" of the line with no text: the answer is negative: there are no "lines" if there is no text. This is not how text controls (all of them) work. May I ask why, by the way?

[EDIT]
New update from OP (picture) show that the requested feature is not selection, so this answer is not applicable.
This is not my fault though.
Please see my other Answer.

—SA
 
Share this answer
 
v4
Comments
Venkatesh Mookkan 9-Mar-11 21:15pm    
I guess, he basically wants to highlight the row even if you don't have text.
Sergey Alexandrovich Kryukov 9-Mar-11 21:30pm    
Thank you for the note; I'll update my answer.
--SA
Venkatesh Mookkan 9-Mar-11 21:47pm    
Negative?!!? Isn't that rude?

I would say, it is possible but need some work to do. There are applications which highlight the current row. Even VS 2010 has an extension which will highlight the Current row. ;)

By the way, I appreciate that you are willing to acceptance nature.
Sergey Alexandrovich Kryukov 9-Mar-11 22:31pm    
Venkatesh, I don't even understand you.

This is certainly some problem of language if you consider word "negative" as rude. How about "-" operator? :-)

I also did not understand you last sentence.

Let me bring to your attention that 1) I still did not get the answer what is highlighting; is it selection or something else; the question is not so trivial; because there highlighting which is not selection, 2) the problem in question is not selecting a whole line but a line in empty text. Not that is is impossible, but the meaning of it is not defined, set aside the purpose.

--SA
Venkatesh Mookkan 9-Mar-11 22:40pm    
Rude is not like rude to the person. When you say Negative it is like you can't go further. Sorry if I used word for this. :)

My last sentence: You said, you updated the answer after I stating that the user want to Highlight/Selection the whole line.

Explanation for the points:
1. I know Highlight is different from Selection. But in my opinion, the questionnaire is asking for Highlight.
2. I agree.

We are arguing, but the questionnaire is silent. What are we doing?
your question is little bit confusing for me as I getting you want to highlight Line of richtextbox either its is complete filled or not if so then I found this link-[Highlight current row in richtextbox control][^]. read the thread it might help you.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Mar-11 13:18pm    
Unfortunately, according to OP updated description this is not what OP wants.
I already answered in a similar way, why repeating it?
--SA
RaviRanjanKr 10-Mar-11 14:06pm    
I've already mentioned in my answer is that "I am in Confusion about OP question" so I've just refer a link to navigate and found exact solution as per requirement.

SA:- I already answered in a similar way, why repeating it?
oh! I've not focused on your answer so mistakenly its may be repeated or in similar way. its my fault :)
Answering follow-up Question after the picture was submitted:

You certainly did not explain it properly in first place. What you show on the picture (thank you, you finally answered my questions by this post, but you better put in in your Question)... this is what was my last guess in our guesswork with Venkatesh. Too bad you came back that late, so all we did was guesswork.

Of course, it is possible, but this presentation if far, really far away from existing rich text functionality. I'm almost 100% much sure the UI you show is not based on rich text. Best thing to do would be to create a brand new editor code. I'm not joking, because I know what other teams did (not for the sake of you highlight but for more serious reasons). If you really would like to bite a bullet, please look at the editor implementation in Sharp develop: http://en.wikipedia.org/wiki/SharpDevelop[^], http://sharpdevelop.com/[^] — full source code is available.

You can still want to use RichTextBox, this would be <d>very difficult. This component is strongly text-oriented. Even finding a relative coordinate in the scrolled area is difficult, because all measurements are done in character positions, and all characters and lines are of different sizes (this problem is solvable in WPF though). So first big problem will be just to find coordinates of you horizontal strip. How about width? You will have to locate the text line and calculate its bounding size. And rendering of this thing is a real nightmare. You cannot just put a control on top of the RichTextBox would block your mouse/keyboard interaction with the text. Low-level rendering in RichTextBox? Even if you do this, how can it interact with all changes in the line underneath? And so on. I would more easily write a brand new edit component…

Do you really want to break your teeth on this problem? I would suggest you spend your time on something more useful.

—SA
 
Share this answer
 
v4
Thank all! It's very useful for me but I think I have to learn more!
 
Share this answer
 
Could any one knows what control used by WinMerge to Highlight complete line?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900