internal static extern int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, DrawTextFlags uFormat);
/// <summary> /// Raises the Paint event /// </summary> /// <param name="e">A PaintEventArgs that contains the event data</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaintBackground(e); //base.OnPaint(e); // do we have an image to draw if (this.Image != null) { if (this.Enabled) { if (this.RightToLeft == RightToLeft.Yes) { e.Graphics.DrawImage(this.Image, this.Width-16, 0, 16, 16); } else { e.Graphics.DrawImage(this.Image, 0, 0, 16, 16); } } else { // fix: use ControlPaint.DrawImageDisabled() to draw // the disabled image // Brad Jones ([email protected]) // 26/08/2004 // v1.3 if (this.RightToLeft == RightToLeft.Yes) { ControlPaint.DrawImageDisabled(e.Graphics, this.Image, this.Width-16, 0, this.BackColor); } else { ControlPaint.DrawImageDisabled(e.Graphics, this.Image, 0, 0, this.BackColor); } } } // do we have any text to draw if (this.Text.Length > 0) { if (this.textRect.Width == 0 && this.textRect.Height == 0) { this.textRect.X = 0; this.textRect.Y = 0; this.textRect.Height = this.PreferredHeight; if (this.RightToLeft == RightToLeft.Yes) { this.textRect.Width = this.Width - this.Padding.Right; if (this.Image != null) { this.textRect.Width -= 16; } } else { if (this.Image != null) { this.textRect.X = 16 + this.Padding.Left; } this.textRect.Width = this.Width - this.textRect.X - this.Padding.Right; } } if (this.RightToLeft == RightToLeft.Yes) { this.stringFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; this.drawTextFlags |= DrawTextFlags.DT_RTLREADING; } else { this.stringFormat.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft; this.drawTextFlags &= ~DrawTextFlags.DT_RTLREADING; } if (this.UseGdiText) { this.DrawGdiText(e.Graphics); } else { this.DrawText(e.Graphics); } } // check if windows will let us show a focus rectangle // if we have focus if (this.Focused && base.ShowFocusCues) { if (this.ShowFocusCues) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } } }
/// <summary> /// Initializes the TaskItem's DrawTextFlags object /// </summary> private void InitDrawTextFlags() { if (this.drawTextFlags == (int) 0) { this.drawTextFlags = (DrawTextFlags.DT_LEFT | DrawTextFlags.DT_TOP | DrawTextFlags.DT_WORDBREAK); } }
public static extern int DrawText( IntPtr hDC, string lpString, int nCount, ref Common.RECT lpRect, DrawTextFlags uFormat );