How to have multiple font style in a single string.
I have a big string and i will append that string to a microsoft word from c# windows application.
I want some characters to be bold... some with big font. like that.
I tried with ordinary HTML tags like < b > bold ..< / b> it wont work..
I want string with mixed font styles.
Text BOLD small BIG
I am Exporting that string to a word file from c# windows application as i mentioned.
Help Much appreciated.
the keyword of your question is RTF, RichText format string see
Better Way of Manipulating RichText in C#?
How to convert a string to RTF in C#?
You can use RTF - see "How to paste a Rich Text Format string into Word with Visual Basic Automation" for an example (in VB.Net, but it would work the same in C#)
There is no style for a string. A string is a list of characters, that's all.
If you want to copy/paste a styled text to word, you'll have to export it in another format first. You could use HTML or RTF.
This lib might help you.
Related
currently, I'm using Richeditbox in my to edit and display formatted text in App. there a now a lot of RichEditBoxes. because its the goal of the App, to show a list of formatted text blocks with different Content. The Performance is really slow and the space in DB is great, I'm storing the text in RTF-format in blobs.
What is the easiest way to show simple formatted Text (eg bold, italic)? I never found a quite sample?
If you just want to display formatted text you have two options.
RichTextBlock is a TextBlock-like counterpart of RichEditBox. It is however more performant as it just displays the content and does not offer editing.
Alternatively there is a MarkdownTextBlock control in the UWP Community Toolkit, which can display simple formatted text in the Markdown format.
I am using tinyMCE editor. I have rtf formatted string in database column which I want to show in the browser editor i.e. tinyMCE. So that, user will edit the text as he wants. But for that I found I need to convert the rtf string in to xml to see it, since my tinyMCE is showing xmls properly. I am able to show the text from rtf string but I misses out the formatting like bold text, red colored text, \n etc. I want to retain all this formatting. How shall I retain the formatting or how shall I display the rtf text with the formatting or how shall I convert rtf text in to xml properly? I want to display rtf text like I am saving it in some rtf file and opening that file in ms word or open office word that way I want to see the format. rtf is Rich Text format.
You should convert your RTF to HTML and use that for TinyMCE, here is a code project article that will get you started :
http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter
I am reading a txt file and writing it's content to another txt file.
Before writing the content to new file i have to change the font of the string (string that is read from another file).
How should i do this.
Please help.
Strings don't inherently have fonts. If the string represents RTF or something like that, then that's a different matter - it's effectively changing the font within the RTF format.
However, if you're just writing a plain text file, it's entirely up to the display client which font it uses.
Sorry!! friend. you can't change the fonts or size of string. C# don't know where your are going to write the string text... Console or any text file or label...
Just think what happens if it supports, lets u set some format to string and in place of writing to a file you are printing to console (Console is not rich in fonts)
anyway !! but if you want to do it, it depends on the type of file you are writting. notepad, or rtf orword document. There you can find changing fonts very easily.
If it is pure text file, then you cannot!
If you are writing a Word Doc, using some Office API then you can!
a simple string has no font. A font is used for printing or displaying a string, but a string itself is only text. If you are talking about some encoded text (like rtf) you are reading, you will need to parse the text into something interpretable and go on from there.
If you only want to put out one or more strings in a textbox using different fonts, you will need to use a control that supports formatting.
I want to be able to read text from a Silverlight TextBlock (TextBlock Control) (Silverlight & C#) and check what formatting (as in: bold, italic, font size, etc...) has been applied to it, so I can store it in an XML file.
Is it possible to find out what formatting has been applied to a piece of text with C# and Silverlight so it can be stored and re-used later? The text would be contained within a textbox or textblock control.
Storage used can be XML but I've just found out Silverlight doesn't support XSL, so just XML.
Regards,
T
Just make sure you give your control a name.
<Textblock x:Name="myTextBlock" />
In your code behind you can then access the TextBlock but calling it's name (myTextBlock).
Here you can add logic like:
if (myTextBlock.FontWeight == "Bold")
{
//Do Something
}
From reading your needs you'll most likely be passing the object to a function and creating your xml file from there. Good luck.
By formatting you mean a phone number or date format?
If yes. Use regular expressions.
Take a look at the System.Text.RegularExpressions namespace. Everything there should help you.
I'm developing an advanced rich text editor in c# but have stumbled upon a problem that I can't seem to grasp.
I have been trying to let users save their documents as Text files (plain text). By using the following:
MyRichTextBox.SaveFile(filepath, PlainText);
But the problem is that when they view that file (which should have been saved as plain text) in Notepad, it shows up with all of the RTF formatting codes whish makes their documents unreadable. Does anybody know of any other way to remove formatting codes from a RichTextBox without having to do too much?
I mean, if there's going to be alot of work involved in finding a workaround to such a simple task, I might as well just create my own RichTextBox control from scratch. Which I'm sure would be very hard to do, but atleast I know that it'll work...
... Sorry for ranting on a little there, hehe...
Thanks All,
Jason.
This should do it:
String txt = MyRichTextBox.Text
File.WriteAllText(filepath, txt);
Alternatively, the way to get the RTF is:
String rft = MyRichTextBox.Rtf;
File.WriteAllText(filepath, rtf);
Have you tried:
RichTextBoxStreamType.PlainText
instead of:
PlainText