Hi Guys,

How I should grab a string form a line in richTextBox object without a selection, but it has the cursor inside it.

How to accomplish this or where I should search for this feature????????

Thanks

[EL-Prince]

Recommended Answers

All 10 Replies

What exactly is it you are looking to do? Just to select a small portion of text, with pre-defined format.
Or is it multi-line RTB, and you want to select one of them?

Actually, I think you didn't get what I want correctly!!!!
For example if I have the following code inside richTextBox

myClass c = new myClass();
c.ShowResults();

What I want is right clicking the ShowResult()
and select a predefined option which called Mark All to find all references in the code by change the background color.

Thanks for your answer.

[EL-Prince]

the rich text box has a Lines[] property, all you need to know is the line number and you can get the entire lines text via that property array. get that line number however you like, via mouse position or whatever you feel.

Yeah, I know the lines property, but actually how I get the current word from the current line if the current line is given by lines property??

I mean lines property gets lines only and it has nothing to do with the current word!!!!!!!!!!

Thanks for your reply

[EL-Prince]

I not really sure what you mean by current word. Infact my answer was based on the title of the thread, I'm not very sure what you want to know.

I am still not getting, what is it you want, and why you want.

Hi guys,

Sorry guys if I'm not very clear to express my problem it might due to my English, but here's a very clear example of what I'm trying to do.

Sometimes you want to find the definition of a certain instance variable in visual studio you simply right click that instance variable and select go to definition without select the instance variable, then Visual Studio move the cursor to the definition directly that's what I'm trying to do.

Thanks a bunch all of you for your sharing.

[EL-Prince]

So, as I understood... you want to have VS like functionality for your text box... which you are using like text editor?

I've haven't solve a problem like this, but if you look into open source IDE's like mono, you might get the functionality from there.

@vibhutirs
Thanks for your sharing, but I couldn't find the source code wit which could run on windows platform only the .msi distribution file, if you have a link of the source code please post it here!!!

[EL-Prince]

if ((pos1 < myRich.Text.Length) && (myRich.Text[pos1].ToString() != "") && (myRich.Text[pos1].ToString() != " "))
            {
                //get word from cursor ( from special char to special char)
				//1. part - from cursor to end of word
                string word = "";
                while (
                       ( pos1 >= 0 )
                       &&
                       ( isNumeric(myRich.Text[pos1].ToString(), System.Globalization.NumberStyles.Integer) || IsInputChar( myRich.Text[pos1] ) )
                      )
                {
                    word = myRich.Text[pos1].ToString() + word;
                    pos1--;
                }
				//2. part - from cursor to begin of word
                WordStart = ++pos1;
                pos2++;
                while (
                       (pos2 < myRich.Text.Length)
                        &&
                       (isNumeric(myRich.Text[pos2].ToString(), System.Globalization.NumberStyles.Integer) || IsInputChar(myRich.Text[pos2]))
                       &&
                       (pos2 >= 0)
                      )
                {
                    word = word + myRich.Text[pos2].ToString();
                    pos2++;
                }
			}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.