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 "\ naaaaaaaaaaaaaaaaaaaaa \ nbbbbbbbbbbbbbbbbbbb \ nccccccccc" 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>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)