By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

write to a text file in a specific font and color.

P: n/a
Hello !
With c# , I want to write to a text file in a specific font and color.

Any ideas ?

Thanks...
May 15 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Niron,

What do you want to write the file on. If you use Graphics object to draw
each line then any of the DrawString overloads accept font and brush object.
If you want show in a textbox control then you can use RichTextBox control
where you can change the color and the font for different parts of the text.
--

Stoitcho Goutsev (100)

"Niron kag" <Niron ka*@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Hello !
With c# , I want to write to a text file in a specific font and color.

Any ideas ?

Thanks...

May 15 '06 #2

P: n/a
Well, a "text" file *has* neither font nor colo[u]r; so - you need to be
more specific: what file format do you mean; HTML would be simple,
presumably using <FONT> or CSS attributes; RTF would be achievable by using
the RichTextBox control; set the text, then manipulate the font etc
(something like below):

// (assumes richTextBox1 declared and assigned at this point)
richTextBox1.Text = "Some Text";
richTextBox1.SelectAll();
richTextBox1.SelectionFont = new Font("Times New Roman", 20);
richTextBox1.SelectionColor = Color.Aquamarine;
richTextBox1.SaveFile("C:\\My.rtf");

Hope this helps,

Marc
May 15 '06 #3

P: n/a

"Niron kag" <Niron ka*@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Hello !
With c# , I want to write to a text file in a specific font and color.

Any ideas ?

Thanks...


Text files (if you mean files with a .txt extension that open in Notepad for
example) don't have such things.

Although the version of Notepad in W2K and XP can support different
fonts/colours etc, this is a local display option on the computer, *not*
formatting information held in the file.

Perhaps you want to use .rtf files? These allow font info and so on. Or
perhaps .html as others suggest.

Depends on why you are trying to achieve this...
James.
May 15 '06 #4

P: n/a
Thank U Marc Gravell,
I wanted to wrote to a file with suffix ".txt" , and I understand I can not.
I need to create ".rtf" file ?!

"Marc Gravell" wrote:
Well, a "text" file *has* neither font nor colo[u]r; so - you need to be
more specific: what file format do you mean; HTML would be simple,
presumably using <FONT> or CSS attributes; RTF would be achievable by using
the RichTextBox control; set the text, then manipulate the font etc
(something like below):

// (assumes richTextBox1 declared and assigned at this point)
richTextBox1.Text = "Some Text";
richTextBox1.SelectAll();
richTextBox1.SelectionFont = new Font("Times New Roman", 20);
richTextBox1.SelectionColor = Color.Aquamarine;
richTextBox1.SaveFile("C:\\My.rtf");

Hope this helps,

Marc

May 15 '06 #5

P: n/a
"Niron kag" <Niron ka*@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
With c# , I want to write to a text file in a specific font and color.


As others have told you, font and colour are "rich text" attributes - text
files are "plain text", so don't support such things.

Why do the files need to be created?

What do you intend doing with them?

Have you maybe considered PDF?
May 15 '06 #6

P: n/a
james ,
How do I create a file with suffix of "rtf" , can U explain it? (Or give me
link)?
Are the function to "write" and "read" from the ".rtf" file different from
the function of ".txt" file ?

Thank U!
"james" wrote:

"Niron kag" <Niron ka*@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Hello !
With c# , I want to write to a text file in a specific font and color.

Any ideas ?

Thanks...


Text files (if you mean files with a .txt extension that open in Notepad for
example) don't have such things.

Although the version of Notepad in W2K and XP can support different
fonts/colours etc, this is a local display option on the computer, *not*
formatting information held in the file.

Perhaps you want to use .rtf files? These allow font info and so on. Or
perhaps .html as others suggest.

Depends on why you are trying to achieve this...
James.

May 15 '06 #7

P: n/a
RTF would be a solution, yes; whether it is the /right/ solution depends on
what you want to do with it. Plenty of others exist - with HTML and RTF
probably the two most common. HTML is more portable (e.g. to other OSes /
platforms) and is easier to read in its native form.

So yes, you need to write in some known format. RTF may suffice - but you
need to figure that out for sure.

Marc
May 15 '06 #8

P: n/a
"Niron kag" <Ni******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
How do I create a file with suffix of "rtf" , can U explain it? (Or give
me
link)?


http://www.google.com/search?sourcei...%22C%23%22+RTF
May 15 '06 #9

P: n/a
Mark Rae ,
this file intend to give indication about success or failure of some
operations.
So I want to create a file for the user - that will be easy to read!
Any ideas?

"Mark Rae" wrote:
"Niron kag" <Niron ka*@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
With c# , I want to write to a text file in a specific font and color.


As others have told you, font and colour are "rich text" attributes - text
files are "plain text", so don't support such things.

Why do the files need to be created?

What do you intend doing with them?

Have you maybe considered PDF?

May 15 '06 #10

P: n/a
Niron kag <Ni******@discussions.microsoft.com> wrote:
this file intend to give indication about success or failure of some
operations.
So I want to create a file for the user - that will be easy to read!
Any ideas?


Create a HTML file with a .HTML extension. It's easy if you simply use
<font> etc. attributes. Text files (.txt) are just sequences of
characters, they can contain no intrinsic color information.

-- Barry
May 15 '06 #11

P: n/a
"Niron kag" <Ni******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
this file intend to give indication about success or failure of some
operations.
So I want to create a file for the user - that will be easy to read!
Any ideas?


Why can't they just view the details on screen? Why do you need to create a
file?
May 15 '06 #12

P: n/a

"Niron kag" <Ni******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
james ,
How do I create a file with suffix of "rtf" , can U explain it? (Or give
me
link)?
Are the function to "write" and "read" from the ".rtf" file different from
the function of ".txt" file ?

Thank U!


I'm afraid I don't know - I'm fairly new to C# myself.
But the link that Mark gave you should help you out with a few examples!
James.
May 15 '06 #13

P: n/a
Mark,
The reason I use file is I want to save all the indications about previous
operations.
Not only per current opration.
shai,

"Mark Rae" wrote:
"Niron kag" <Ni******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
this file intend to give indication about success or failure of some
operations.
So I want to create a file for the user - that will be easy to read!
Any ideas?


Why can't they just view the details on screen? Why do you need to create a
file?

May 16 '06 #14

P: n/a
"Niron kag" <Ni******@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
The reason I use file is I want to save all the indications about previous
operations.
Not only per current opration.


Hmm - maybe some sort of database is in order, then... :-)
May 16 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.