Skybound Rebar

RebarTheme.CreateMenuRenderer Method 

Creates a new RebarMenuRenderer object which renders menus using the current theme.

[Visual Basic]
Overridable Public Function CreateMenuRenderer() As RebarMenuRenderer
[C#]
public virtual RebarMenuRenderer CreateMenuRenderer();

Return Value

A RebarMenuRenderer object which renders menu windows using the current theme.

Remarks

Since menu windows cannot be owner-drawn (only menu items can), it is usually not necessary to ever call this method from your code.

If you create a custom theme, override this method and return a new instance of your custom implementation of RebarMenuRenderer.

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

RebarTheme Class | Skybound.Rebar.Rendering Namespace