Sign in to follow this  

[.net] How to select/HIGHLIGHT one line in a multiline textBox?

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My application is a text comparer consists of Source textBox and Target textBox. After I found differences of Source file and Target file, I put them in a listView with format like this: Line # | Source File | Target File | ------------------------------------------ Line 2 | eat | sleep | Line 5 | Nevada | Los Angeles | if users double-click on one of the item above, the focus / active cursor will DIRECTLY point to the Source textBox and/or Target textBox which LINE containing those words. And that LINE will be HIGHLIGHTED. If it is not possible to HIGHLIGHT 2 textBoxes at the same time, how to HIGHLIGHT 1 textBox only? Thank you very much..

Share this post


Link to post
Share on other sites
Have you looked at how Visual SourceSafe (or similar tool) works? If not, I recommend doing so before posting more questions. This is like the 10th question you've posted on this topic.

Share this post


Link to post
Share on other sites
I look for the difference and saved the line number as a listView item and when user want to point the difference, I did this on the listView1_DoubleClick event:

txtSource is the Source textBox, txtDest is the Destination textBox.

tmp is a int variable to get the listView item containing line number.



array<Char>^ chars = {' '};
array<String^>^ ln = item->Text->Split(chars);

int tmp = Convert::ToInt32(ln[1]) - 1;

txtSource->HideSelection = false;
txtSource->Select(txtSource->GetFirstCharIndexFromLine(tmp),txtSource->Lines[tmp]->Length);
txtSource->ScrollToCaret();
txtDest->Focus();
txtDest->HideSelection = false;
txtDest->Select(txtDest->GetFirstCharIndexFromLine(tmp),txtDest->Lines[tmp]->Length);
txtDest->ScrollToCaret();
listView1->HideSelection = false;
listView1->Select();

The result was: the codes has pointed to both textBox at the same time but just highlight the line containing character..

I still cannot select empty line, I don't know what an empty line contains? Is it " " or "\n" or empty String or null?

And I still cannot select one line full from left side of the textBox to the right side of the textBox.

How to do that?

Thank you very much..

Share this post


Link to post
Share on other sites
I oftenly heard about write/make a custom control. How to do that?
Do you have any code sample?

So I must check if the line is equal to "\r\n" ?

I also have problem here with inserting new lines. Everytime user click button Compare, I compare the line count between Source textBox and Destination textBox. If one of them smaller, I insert new lines.

When users change one of the file and load new file, for case of file that stays in the textBox has fewer line count than the new files, it will be compared in a condition of added new lines.

First of all, a user compare file A ( 30 lines ) and file B ( 26 lines ). To make this equal so that I can select the empty line to show the difference, I must insert 4 new lines.

So, now A = B = 30 lines.

It's done.

Next thing, user pick a new file to replace A with let say C (20 lines), B remains in the textBox (30 lines). To make C equal with B ( 30 LINES ! ) I must insert 10 empty line. So, it is wrong. The correct one should only 26(actual B line count) - 20(actual C line count) = 6 lines NOT 30(modified B line count) - 20 = 10.

Do you get what I mean?

How to check and remove all the added lines when user pick a new file?


Ok, thank you everyone for the information.

[Edited by - chrisliando on February 18, 2008 9:18:53 PM]

Share this post


Link to post
Share on other sites

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this