我记得c#中的字符串,好象有类似这样的表示方法的。但具体怎么忘记了。

zcwymfyxzg 2011-12-08 01:57:53
例如(下面代码是错误的,但我记得正确的写法,与下面是很相似的):

textBlock_00.Text += "<FontSise=30>自由</FontSize>";
textBlock_00.Text += "<FontFamily="SimSun">飞翔</FontSize>";
textBlock_00.Text += "<Color="Red">天空</FontSize>";

...全文
99 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcwymfyxzg 2011-12-08
  • 打赏
  • 举报
回复
我的是在WPF,难道所以不行?

[Quote=引用 13 楼 zyloveyrf 的回复:]

引用 12 楼 zcwymfyxzg 的回复:

试了,不行。

引用 9 楼 keenweiwei 的回复:

textBlock_00.Text += @"<FontSise=30>自由</FontSize>";

在webform里面确实行
[/Quote]
萧炎 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zcwymfyxzg 的回复:]

试了,不行。

引用 9 楼 keenweiwei 的回复:

textBlock_00.Text += @"<FontSise=30>自由</FontSize>";
[/Quote]
在webform里面确实行
zcwymfyxzg 2011-12-08
  • 打赏
  • 举报
回复
试了,不行。

[Quote=引用 9 楼 keenweiwei 的回复:]

textBlock_00.Text += @"<FontSise=30>自由</FontSize>";
[/Quote]
zcwymfyxzg 2011-12-08
  • 打赏
  • 举报
回复
这个可以。
但我记得,我上面的方法,也是可以的,也方便。

就是忘记了具体的格式写法。

[Quote=引用 10 楼 zyloveyrf 的回复:]

引用 8 楼 zcwymfyxzg 的回复:
你这个,只能设置全部,不能设置部分。

引用 5 楼 zyloveyrf 的回复:

txtBox.ForeColor = Color.Red;
txtBox.Text="asdasdas";

那不能用文本框 用richbox
ichTextBox this.richTextBox1.SelectionStart=0; \\开始选……
[/Quote]
萧炎 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 zcwymfyxzg 的回复:]
你这个,只能设置全部,不能设置部分。

引用 5 楼 zyloveyrf 的回复:

txtBox.ForeColor = Color.Red;
txtBox.Text="asdasdas";
[/Quote]
那不能用文本框 用richbox
ichTextBox this.richTextBox1.SelectionStart=0; \\开始选中位置
this.richTextBox1.SelectionLength = 1; \\ 结束选中位置
this.richTextBox1.SelectionColor = Color.Red; \\字体色
this.richTextBox1.SelectionBackColor = Color.Yellow; \\背景色
ijwsoft 2011-12-08
  • 打赏
  • 举报
回复
textBlock_00.Text += @"<FontSise=30>自由</FontSize>";
zcwymfyxzg 2011-12-08
  • 打赏
  • 举报
回复

你这个,只能设置全部,不能设置部分。

[Quote=引用 5 楼 zyloveyrf 的回复:]

txtBox.ForeColor = Color.Red;
txtBox.Text="asdasdas";
[/Quote]
zcwymfyxzg 2011-12-08
  • 打赏
  • 举报
回复
颜色还是没有变红色啊。显示出来的结果就是:<Color=\"Red\">天空</FontSize>



[Quote=引用 4 楼 sandy945 的回复:]

那里不行,别光说不行
[/Quote]
朕赐你肥皂 2011-12-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zyloveyrf 的回复:]

txtBox.ForeColor = Color.Red;
txtBox.Text="asdasdas";
[/Quote]


这个才是对的,一般文本框是无法设置颜色的,OVER,结贴
萧炎 2011-12-08
  • 打赏
  • 举报
回复
txtBox.ForeColor = Color.Red;
txtBox.Text="asdasdas";
阿非 2011-12-08
  • 打赏
  • 举报
回复
那里不行,别光说不行
zcwymfyxzg 2011-12-08
  • 打赏
  • 举报
回复
1楼2楼的尝试过了,还是不行。
阿非 2011-12-08
  • 打赏
  • 举报
回复
textBlock_00.Text += "<Color=\"Red\">天空</FontSize>";

ayzen1988 2011-12-08
  • 打赏
  • 举报
回复
FontSise
FontFamily
Color
對應的屬性都換成單引號
如下再試

textBlock_00.Text += "<Color='Red'>天空</FontSize>";

110,571

社区成员

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

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

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