如何突出,或在运行时动态改变一些单词的颜色标签吗? [英] How to highlight or change the color of some words in a label dynamically at runtime?

查看:131
本文介绍了如何突出,或在运行时动态改变一些单词的颜色标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些文本的标签,我想强调或更改一些单词的颜色的标签的文本,而不是全部的话。它必须是动态的。有什么建议?

I have a label containing some text and I want to highlight or change the color of some words in the text of the label and not all of the words. It has to be dynamic. Any suggestions?

这是对C#与ASP.NET用户控件在SharePoint中的WebPart

It's for c# with ASP.NET in a user control in webpart in sharepoint

推荐答案

在服务器端,你可以只嵌入一些HTML在标签的文本(VB):

On the server-side, you could just embed some Html in your Label's text (VB):

myLabel.Text="Some normal text <span style='color: red;'>some red text</span>"

这是基本的机制,但动态可以在这里意味着很多东西。如果您张贴究竟你在做什么一些更多的细节,我也许能帮助更多。

That's the basic mechanism, but 'dynamic' could mean a lot of things here. If you post some more details about exactly what you're doing, I might be able to help more.

还有一个想法:作为罗布·艾伦指出的那样,立即控制可能是一个稍微好一点的选择,在这种情况下,因为它的预定发射原始的HTML,而标签封装在一个跨距中的文本,使整个事情可以被格式化容易。

One more thought: as Rob Allen pointed out, the Literal control may be a slightly better choice in this situation since it's intended to emit raw Html, whereas the Label wraps the text in a span so that the whole thing can be formatted easily.

检查了这一点了解详情:<一href=\"http://stackoverflow.com/questions/510998/what-literal-control-is-used-for-in-asp-net-and-difference-between-it-and-label\">StackOverflow:文字与标签

Check this out for more details: StackOverflow: Literals versus Labels

有关记录,视情况而定,我认为一个标签,实际上可能是好的在这里。

For the record, depending on the situation I think a Label may actually be okay here.

这篇关于如何突出,或在运行时动态改变一些单词的颜色标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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