怎样实现在同一个字符串中使用不同的字体和颜色???

NoirCheng 2007-02-02 12:35:05
例如:
string str = "我 and 你";
如何使and的字体和颜色与其余两个不一样?
用代码如何实现?
...全文
585 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
松花皮蛋 2008-05-08
  • 打赏
  • 举报
回复
richTextBox支持,richTextBox可以帮助你实现这个功能.Select方法和SelectionColor

给段代码给你看,能实现不同颜色显示
string str = "010222333344";
this.richTextBox1.Text = str;
this.richTextBox1.Select(0, 3);
this.richTextBox1.SelectionColor = System.Drawing.Color.Red;
this.richTextBox1.Select(3, 3);
this.richTextBox1.SelectionColor = System.Drawing.Color.Blue;
this.richTextBox1.Select(6, 3);
this.richTextBox1.SelectionColor = System.Drawing.Color.Green;
this.richTextBox1.Select(9, 2);
this.richTextBox1.SelectionColor = System.Drawing.Color.Brown;


兄弟,你得给点分给我呀.我还有几分就升级了
viena 2007-02-02
  • 打赏
  • 举报
回复
回答的都白忙活了,幸亏我没答
碰到这样问问题的真让人哭笑不得!
honkerhero 2007-02-02
  • 打赏
  • 举报
回复
晕,比楼主晚了一步,WINFORM就拆开,放在不同的LABEL中,给LABEL设置文本颜色
可以放在其它控件上
NoirCheng 2007-02-02
  • 打赏
  • 举报
回复
那wimform程序呢 是不可以实现吗?
honkerhero 2007-02-02
  • 打赏
  • 举报
回复
该说的楼上都说了,帮你顶一下
NoirCheng 2007-02-02
  • 打赏
  • 举报
回复
DeanMonica(夏天的叶子)
----------------------------------------------------------

我写的是wimform程序 也可以那样写吗
懒牛科技 2007-02-02
  • 打赏
  • 举报
回复
如果是web程序可以这样。
string str1;
string str2=string.Empty;
str1 = "i and you ";
str2=str1.Replace("and","<font color=red> and </font>");
Response.Write(str2);
viena 2007-02-02
  • 打赏
  • 举报
回复
字符串是内存变量,没有字体和颜色的说法
DeanMonica 2007-02-02
  • 打赏
  • 举报
回复
string str = "<font color='black'>我</font> and <font color='red'>你</font>";
awenhao 2007-02-02
  • 打赏
  • 举报
回复
比如
richTextBox1.Text = "0123456789";
richTextBox1.SelectionStart = 3;
richTextBox1.SelectionLength = 4;
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionLength = 0;
awenhao 2007-02-02
  • 打赏
  • 举报
回复
wimform需要richTextBox支持,richTextBox可以帮助你实现这个功能,因为仅仅字符串不可能包含颜色等属于字体的信息,字体属于显示时的问题,所以需要的到第三方控件的支持才可以实现,刚才几个都是说的web browser支持,那么在桌面程序中,.net中需要richTextBox的支持,比如 SelectionFont和SelectionColor属性可以让你按照自己的意思去设置自体和属性。自己看看吧。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧