关于重绘标签控件 [英] About redraw label control

查看:94
本文介绍了关于重绘标签控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现标签控制文本显示前面的四个字符都是白色的,后一个字是全红色的。 
以下是我的代码:
< pre lang = c# >
//我用过:作为分隔符
public Rectangle DeflateRect(Rectangle rect,Padding padding)
{
rect.X + = padding.Left;
rect.Y + = padding.Top;
rect.Width - = padding.Horizo​​ntal;
rect.Height - = padding.Vertical;
返回rect;
}


protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);


矩形r = DeflateRect(base.ClientRectangle,base.Padding);

if(this.Text.Length> 0)
{
string [] str = this.Text.Split(new char [] {':'});
if(str.Length> 0)
{
TextRenderer.DrawText(e.Graphics,
this.Text.Substring(0,str [0] .Length + 1 ),this.Font,r,Color.White,base.BackColor,TextFormatFlags.Left);


TextRenderer.DrawText(e.Graphics,
this.Text.Substring(str [0] .Length + 1,str [1] .Length),this.Font ,r,Color.Red,base.BackColor,TextFormatFlags.Right);
}
}
}



< / pre >

< pre lang = vb > 然而,我遇到了以下问题:
当& quot; \ naaaaaaaaaaaaaaaaaaaa \ nbbbbbbbbbbbbbbbbbb \ nccccccccc& quot;当控制字生成器和原始偏移量时,将显示多个换行符,它看起来像控制字上显示的两种颜色< / pre >

解决方案



查看此链接,希望这样可以解决您的问题。



如何在标签中使用两种颜色的文件在Windows应用程序的c#中 [< a href =http://www.codeproject.com/Questions/337614/how-to-use-two-colors-in-label-for-text-in-csharptarget =_ blanktitle =新窗口> ^ ]



如何在标签中为c#中的文本使用两种颜色 [ ^ ]



http:/ /www.daniweb.com/software-development/csharp/threads/226320/different-character-colours-in-a-label-or-any-other-control [ ^

I want to achieve label control text display in front of four characters are white, the latter word is all red.
The following is my code:
<pre lang="c#">
    //I have used: as a separator
    public Rectangle DeflateRect(Rectangle rect, Padding padding)
        {
            rect.X += padding.Left;
            rect.Y += padding.Top;
            rect.Width -= padding.Horizontal;
            rect.Height -= padding.Vertical;
            return rect;
        }


        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);


            Rectangle r = DeflateRect(base.ClientRectangle, base.Padding);

            if (this.Text.Length > 0)
            {
                string[] str = this.Text.Split(new char[] { ':' });
                if (str.Length > 0)
                {
                    TextRenderer.DrawText(e.Graphics,
                       this.Text.Substring(0, str[0].Length + 1), this.Font, r, Color.White, base.BackColor, TextFormatFlags.Left);


                    TextRenderer.DrawText(e.Graphics,
                     this.Text.Substring(str[0].Length + 1, str[1].Length), this.Font, r, Color.Red, base.BackColor, TextFormatFlags.Right);
                }
            }
        }



</pre>

<pre lang="vb">However, I encounter the following problems:
           When &quot;\ naaaaaaaaaaaaaaaaaaaaa \ nbbbbbbbbbbbbbbbbbbb \ nccccccccc&quot; multiple newline character will be displayed when the control word generator and the original offset, it looks like two kinds of color displayed on the control word</pre>

解决方案

HI,
Check this link ,hope so this will solve your question.

how to use two colors in label for text in c# in Windows Application[^]

how to use two colors in label for text in c#[^]

http://www.daniweb.com/software-development/csharp/threads/226320/different-character-colours-in-a-label-or-any-other-control[^]


这篇关于关于重绘标签控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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