How to read selected text on richTextBox? - c#

There is a richTextBox that has string. I want to select a few characters on the richTexBox by mouse and save them in a variable. I use this method:
richTextBox1.SelectedRtf;
It shows me selected characters but is has some additional string and i don't want them. How can I remove them?
This is additional string:
{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1065\uc1 }

try
richTextBox1.SelectedText
Here is the msdn link for more information
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectedtext(v=vs.110).aspx

Selection.Text property will return the selected text of Rich Edit Text box.
richTextBox1.Selection.Text

RichTextBox.SelectedText? may be?
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectedtext(v=vs.110).aspx

use this
richTextBox1.SelectedText (property)

Related

making some words bold in textbox winform

Maybe some of you can help me with the following problem. I want some words bolded in a textbox(winforms).
I have a string _descripton variable containing some description text. For example:
“ this is a description of a \b car \b0………… ”. Im trying to replace the string format with richtextformat like:
string _makebold = _description.Replace("\b", #"{\rtf1\ansi \b").Replace("\b0", " \b0.}");
to get the following result: this is a description of a #"{\rtf1\ansi \b car\b0.}"……….
And finally setting the text property of the richtextbox1:
richTextBox1.Text = _makebold;
I cant get that specific word bolded in a richTextbox and textbox doenst work either.
can anyone help me with a solution?
Thanks!
You can use Rtf property of the rich text box control.
For example, the following text adds the text "This text is in bold." to an existing RichTextBox control.
See this MSDN link.
richTextBox1.Rtf = #"{\rtf1\ansi This is in \b bold\b0.}";

Edit RichTextBox programmatically without losing formatting

I have formatted text in the rtf file and I load it to my richTextBox. It works fine, but then I want to remove some text parts programmatically. If I do like that:
richTextBox.LoadFile("TextFile.rtf");
richTextBox.Text = richTextBox1.Text.Substring(fromPosition, length);
text formatting disappears. I've tried to work with richTextBox.Lines, but there is no delete or edit function. All I need is to delete parts of loaded text without losing its formatting. Is it possible?
Thanks in advance.
To remove text you first select it, programmatically by setting SelectionStart and -Length. Then you use the Cut Method:
richTextBox1.SelectionStart = 20;
richTextBox1.SelectionLength = 120;
richTextBox1.Cut();
If you want to avoid putting the removed text to the clipboard you can set it to "" instead of 'cutting' it:
richTextBox1.SelectedText = ""

highlight certain text in a textbox in asp.net

I need TextBox in asp.net to highlight some text when certain event occurs while text is being typed (as in Microsoft Word spell check feature).
I have been using freetextbox, it highlights the text on a button click but not automatically.
How to do that?
Should I use another control?
You can use a RichTextBox for doing it.
With RichTextBox, you can color or highligh single lines or words.
// select characters from index 0 to 9
richTextBox1.Select(0, 10);
//will color the selected text.
richTextBox1.SelectionColor = Color.Green;
Check this link for a tutorial.
You can use jquery and check for each keypress, when your word combination is met you can use css to highlight text.
function is .keypress() - more on keypress

How to display data inside a textbox?

My question is that I have extracted data from a file and pushed into a string variable.
I have a FORM created in visual studio having a text box, so I want to display that extracted data in textbox created.
How can achieve this?
You can do it like this:
yourTextBox.Text = yourString;
For a TextBox, it is just
myTextBox.Text = myStringVariable;
But if the data is large, you may want to consider the RichTextBox control instead.
This is all assuming you're using Windows Forms...
string strName="someone";
TextBox1.Text=strName;
If you trim the data to remove the unwanted trailing spaces if there is any.
TextBox1.Text=strName.Trim();

Reporting Services paragraf

How to add paragraf to Microsoft Reporting textbox?
When i put empty chars, they are not rendered, i try with Functions Space, LSet... VbTab....
For example
i want
This is text
But i get
This is text
Thanks in advance.
To do this, put the following in the Value property of your Report TextBox:
=" Text here"
This will handle the whitespaces.

Categories

Resources