当前位置:编程学习 > C#/ASP.NET >>

如何改变linkLabel中单个字的颜色?

我在form中有一个linkLabel,显示文字是“中秋快乐”。
现在我希望其中的“中秋”两个字用红色字体显示,“快乐”用黑色字体。请问如何在一个linkLabel中实现上述效果? --------------------编程问答-------------------- 最原始的:
<asp:LinkButton ID="LinkButton1" runat="server"><font color="red">中秋</font><font color="black">快乐</font></asp:LinkButton>
--------------------编程问答-------------------- <asp:linkbutton ...><span class="red">中秋</span><span class="black">快乐</span></asp:linkbutton>

在css中
.red { color: red }
.black { color: black }
--------------------编程问答--------------------
引用 1 楼 guwei4037 的回复:
最原始的:
<asp:LinkButton ID="LinkButton1" runat="server"><font color="red">中秋</font><font color="black">快乐</font></asp:LinkButton>

小弟愚钝,请问如何在winform中用linkbutton呢?工具箱里没有啊。 --------------------编程问答-------------------- 晕,是winform?好吧,你参考一下。
 private void Form1_Load(object sender, EventArgs e)
        {
            this.linkLabel1.Paint += linkLabel1_Paint;
            this.linkLabel1.Text = "中秋快乐";
        }

        private void linkLabel1_Paint(object sender, PaintEventArgs e)
        {
            string str = linkLabel1.Text;
            string strA = str.Substring(0, str.Length / 2);
            Point point = new Point(linkLabel1.Padding.Left, linkLabel1.Padding.Top);
            TextRenderer.DrawText(e.Graphics, str, linkLabel1.Font, point, Color.Black);
            TextRenderer.DrawText(e.Graphics, strA, linkLabel1.Font, point, Color.Red);
        }

效果:
--------------------编程问答-------------------- http://bbs.csdn.net/topics/390588871
帮你做了一个
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,