I am trying to write data to an RTF file and set certain characters to a different color. I found out how to do it in a box but I can't figure out how to write it to a file.
If by "do it on a box" you mean RichTextBox you can use the RichTextBox.SaveFile() mothod.
Take a look here.
Related
I would like to create a Richtextbox which load a huge file (several pages of text in some format) and based on format it formats the text (let's say it display html).
I found how to change format of text using selection, but that is very slow and resource expensive. Is there a way to append a preformatted text to Rich Text Box? So that I can format each element and then append it.
This might help you if not the answer you are looking for
But RichTextBox.CanPaste Method determines whether you can paste information from the Clipboard in the specified data format. Please see link the for the System.Windows.Forms.DataFormats it will support
I'm using dynamic RichTextBox control in C# 2.0 and I want to insert "\scaps" in RTF so that if the file is saved programatically and then opened in MS-Word certain text be seen smallcaps.
Can anyone tell me the code as how to insert the tag?
Well, you can access the rich text directly through the Rtf property on the rich text box.
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