Basically in RichEditBox you can paste text and it can automatically format that pasted text according to what you copied. I am wondering how to set a specific part of the document, such as a word, or sentence, to a specific form of font colour, or font style, or any other properties regarding text.
I cannot find any real documentation on how to do such a thing.
EDIT:
I found:
richEditBox.Document.GetRange(3, 10).CharacterFormat.ForegroundColor = Windows.UI.Colors.Blue;
If someone knows something nicer, post please.
Simply use
richEditBox.Document.GetRange(3, 10).CharacterFormat.ForegroundColor = Windows.UI.Colors.Blue;
Are you looking for something like this?
http://msdn.microsoft.com/en-us/library/0dhsw8eb(v=vs.90).aspx
Related
I want to be able to bind content control fields to each others' values. Basically if you change a field at the top, all others in the document also update to that. I'm replacing hundreds of individual variables, each with 100 duplicates. There is a better way than the 'Find and Replace Tool'.
Here is a sample document directly from Microsoft's site that shows exactly what I would like to be able to do:
https://omextemplates.content.office.net/support/templates/en-us/tf03444179.dotx
When the '' value is changed, all others in the document update.
I've already looked at plenty of solutions like: c# word interop find and replace everything
But they do not dynamically respond during run-time. In other words you have to go in and change which string you want to replace for each value.
Been looking for a while now, thanks in advance if anyone else can figure this out.
I have a problem. When i start working with RichTextBox (it is empty) I cannot change format to Bold.
I try to type (CTRL+B) but after I typed something the text is normal (not bold).
The text only changes format when I type something before. This happens again when I SelectAll and Clear all Content.
Is it bug in RichTextBox, or I can do something with it.
Best Regards,
_alexiej
Well, it's normal, usually you decide what is bold or not after you've written the text. If you want this button to act like ( on off ) you have to change it yourself.
I have code that has chemical compounds that have small font for the subscript. I currently have this code that transfers it from one RichTextBox to another one on a Button click.
myRichTextBox.Text += otherRichTextBox.Text
In otherRichTextBox I have the compound with varying font sizes however when I do this I end up with a string in myRichTextBox that doesn't keep the varying font sizes and sets them all to the boxes main properties font and size.
From the documentation on msdn:
"The Text property does not return any information about the formatting applied to the contents of the RichTextBox. To get the rich text formatting (RTF) codes, use the Rtf property."
So to assign the value, with formatting, use this:
myRichTextBox.Rtf = otherRichTextBox.Rtf;
I've replaced += with = because I'm not sure you meant to append the value, rather than just replace it. If you do use +=, you may run into issues due to the "rtf" codes being appended one after the other. However, give it a try... you may not run into any issues at all.
To copy text including formatting you should use the usual RTB way:
Make a Selection and then act on it!
This is the way to go, no matter what you do:
Style your text with SelectionFont, SelectionColor, SelectionAlignment etc..
Insert or remove text with Cut, Copy or Paste
Find text or AppendText
Here is how to do what you asked about:
otherRichTextBox.SelectionStart = 0;
otherRichTextBox.SelectionLength = otherRichTextBox.Text.Length;
myRichTextBox.AppendText(otherRichTextBox.SelectedText);
To insert the portion of text at position n you write
otherRichTextBox.SelectionStart = 0;
otherRichTextBox.SelectionLength = otherRichTextBox.Text.Length;
myRichTextBox.SelectionStart = n;
myRichTextBox.SelectionLength = 0;
myRichTextBox.SelectedText = otherRichTextBox.SelectedText;
You need to go by the rule anytime you want to change formatted text in pretty much any way!
A little bit involved but guaranteed to work correctly as it goes by the book.
To simply 'clone' the full text, go by Grant's code:
myRichTextBox.Rtf = otherRichTextBox.Rtf;
It is possible to work with the raw Rtf codes, if you know what you are doing, but even if some things may still look ok for a while because some errors and most redundancies get ignored, it has a tendency to collect crap.. So you should follow the golden rule:
Make a Selection and then act on it!
Update: Here is a nice way to solve your problem correctly with only two lines! (But you still need to live by the rule..)
I would like to know if there is an easier way to add any kind of visual separation like a line between text lines in a Richtextbox?
If not, is there another component that I can use in a Form that would be able to do this for text lines?
Thank you.
It has been a few years, but at one point I wrote a RichTextBox wrapper that ended up manipulating the underlying markup. It wasn't pretty and it wasn't for the faint of heart, but it did work. I ended up using it to highlight some text I believe.
The key thing you need to know is the specification for the RTF markup language: http://en.wikipedia.org/wiki/Rich_Text_Format should get you started.
The RichTextBox class documentation and the Document property should get you started at modifying the underlying structure of the document after loading or during editing.
I have textbox which accepts string for File name. The user can give/type any name for textbox, even he copy text (Multilingual text) and paste in the textbox. He can copy from any source.
The issue is, how do i detect the 'Language' of copied text which is pasted in textbox and
display the text in that corresponding language?
There is a .net library that does the job:ntextcat ... and ... it`s open source.
Also, you can use google-api-for-dotnet to the actual translate.
May be ill think of having a common words in a dictionary for each language and looking it up when user pastes it. If i find it in any of these dictionary item, then ill know its language type. May not be the best solution your looking for. Open to experts comment here.