Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
XML
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>
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900