以特定字体和颜色写入文本文件。 [英] write to a text file in a specific font and color.

查看:81
本文介绍了以特定字体和颜色写入文本文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

使用c#,我想写一个特定字体和颜色的文本文件。


有什么想法吗?


谢谢......

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

Any ideas ?

Thanks...

推荐答案

Niron,


你是什么?想要写文件。如果你使用Graphics对象每行绘制

,那么任何DrawString重载都会接受字体和画笔对象。

如果你想在文本框控件中显示那么你可以使用RichTextBox控制

你可以改变文本不同部分的颜色和字体。

-


Stoitcho Goutsev( 100)


" Niron kag" < Niron ka*@discussions.microsoft.com >在消息中写道

新闻:6C ********************************** @ microsof t.com ...
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...
你好!
使用c#,我想写一个特定字体和颜色的文本文件。

任何想法?

谢谢......
Hello !
With c# , I want to write to a text file in a specific font and color.

Any ideas ?

Thanks...



好吧,一个文本 file *既没有字体也没有colo [u] r;所以 - 你需要更具体:你的意思是什么文件格式; HTML很简单,

大概使用< FONT>或CSS属性;使用RichTextBox控件的
可以实现RTF;设置文本,然后操作字体等

(如下所示):


//(假设此时声明并分配了richTextBox1)

richTextBox1.Text =" Some Text" ;;

richTextBox1.SelectAll();

richTextBox1.SelectionFont = new Font(" Times New Roman" ,20);

richTextBox1.SelectionColor = Color.Aquamarine;

richTextBox1.SaveFile(" C:\\My.rtf");


希望这会有所帮助,


Marc
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




" Niron kag < Niron ka*@discussions.microsoft.com >在消息中写道

新闻:6C ********************************** @ microsof t.com ...

"Niron kag" <Niron ka*@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
你好!
使用c#,我想写一个特定字体和颜色的文本文件。

任何想法?

谢谢...
Hello !
With c# , I want to write to a text file in a specific font and color.

Any ideas ?

Thanks...




文本文件(如果你的意思是扩展名为.txt的文件在记事本中打开

例子)没有这样的东西。


虽然W2K和XP中的记事本版本可以支持不同的

字体/颜色等,这个是计算机上的本地显示选项,*不*

文件中保存的格式信息。


也许你想使用.rtf文件?这些允许字体信息等。或者

或许.html正如其他人所说的那样。


取决于你为什么要努力实现这个目标...

詹姆斯。



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.


这篇关于以特定字体和颜色写入文本文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆