[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1546
  • Last Modified:

How to "get" text in text area?


I'm developing a toolbar for Internet Explorer...
One of its functions, is to surround text in a text area with attributes....

In other words... if the user is typing something (like this question I'm typing),
then he/she selects a sentence like: Word Word Word Word
then click a button on toolbar that will "process" the selected word/sentence...

By process I mainly mean adding an attribute before/after the sentence...
so it becomes something like:
[b] Word Word Word Word [/b]
or <i > Word Word Word Word </i >

So my questions:
- how to get the selected text only (not the un-selected text in the same textbox)... ?
- Once the string is captured, how to return the selected/marked text to the textbox with the attributes??

I hope I was able to explain what I need :)
1 Solution
mary_MAuthor Commented:
> Guru on this subject..

I thought the this should be the level of the person who is answering the question (not me) :-)
But after posting the question, I found that label:

Author:  mary_M, Limited Member
Guru on this subject.

Well... I am NOT Guru on this subject... it was a mistake, sorry :)
Hi Mary,
You need to use Rich Text Box control instead of textbox to achieve the functionality you are asking.
Under button's click event add the following code ...
            int selectedTextLength = richtextBox.SelectedText.Length;
            if (selectedTextLength > 0)
                richtextBox.SelectionFont = new Font(richtextBox.Font.Name, richtextBox.Font.Size,               FontStyle.Bold);

Let me know for further assistance.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now