Skybound Rebar

ControlRenderer.DrawText Method (Graphics, String, Font, Color, Point, TextRenderFlags)

Draws text at the specified location using the specified Graphics object, font, color and rendering flags.

[Visual Basic]
Overloads Public Shared Sub DrawText( _
   ByVal graphics As Graphics, _
   ByVal text As String, _
   ByVal font As Font, _
   ByVal foreColor As Color, _
   ByVal location As Point, _
   ByVal flags As TextRenderFlags _
)
[C#]
public static void DrawText(
   Graphics graphics,
   string text,
   Font font,
   Color foreColor,
   Point location,
   TextRenderFlags flags
);

Parameters

graphics
The Graphics object in which to draw the text.
text
The text to draw.
font
The Font to apply to the drawn text.
foreColor
The Color to apply to the drawn text.
location
The co-ordinates where the text is drawn..
flags
A bitwise combination of the TextRenderFlags values.

Remarks

You can manipulate how the text is drawn using the flags parameter to pass a combination of TextRenderFlags values. The GetTextRenderFlags method provides a convenient means of obtaining the default set of flags to draw text using a ControlRenderer.

If either font, graphics or text is a null reference (Nothing in Visual Basic), no text will be drawn.

DrawText uses the TextRenderFlags.StandardDrawing flag to determine whether to use GDI or Graphics.DrawString to draw the text.

Example

This example includes the two event handlers required to owner-draw a menu item. Assume that there is a themed Rebar control on the same form called rebar1.

/// <summary>
/// Handles the MeasureItem event for a menu item.
/// </summary>
private void menuItem1_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
{
    // obtain the menu renderer used by the rebar control
    RebarMenuItemRenderer rend = rebar1.Theme.CreateMenuItemRenderer(sender as MenuItem, e);
    
    // set our custom text
    rend.Text = "Custom long text";
    
    // measure the size of the item
    Size sz = rend.MeasureItem();
    e.ItemHeight = sz.Height;
    e.ItemWidth = sz.Width;
}

/// <summary>
/// Handles the DrawItem event for a menu item.
/// </summary>
private void menuItem1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
    // obtain the menu renderer used by the rebar control
    RebarMenuItemRenderer rend = rebar1.Theme.CreateMenuItemRenderer(sender as MenuItem, e);
    
    // invoke the standard background, image and arrow drawing methods
    rend.DrawBackground(e.Graphics);
    rend.DrawImage(e.Graphics);
    rend.DrawArrow(e.Graphics);
    
    // draw our custom text
    ControlRenderer.DrawText(e.Graphics, "Custom long text", rend.Font, rend.ForeColor, rend.GetTextBounds(),
        rend.GetTextRenderFlags());
    
    // draw the shortcut text
    ControlRenderer.DrawText(e.Graphics, rend.ShortcutText, rend.Font, rend.ForeColor, rend.GetTextBounds(),
        rend.GetTextRenderFlags() | TextRenderFlags.AlignFar);
}

See Also

ControlRenderer Class | Skybound.Rebar.Rendering Namespace | ControlRenderer.DrawText Overload List