Creates a new RebarMenuItemRenderer object which renders menu items using the current theme.
A RebarMenuItemRenderer object which renders menu items using the current theme.
The Create methods of a RebarTheme implement a factory design pattern. When you want to draw using a theme, first create a renderer by calling a Create method, and then call the methods on the new renderer to perform the required drawing.
If you create a custom theme, override this method and return a new instance of your custom implementation of RebarMenuItemRenderer.
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);
}
RebarTheme Class | Skybound.Rebar.Rendering Namespace | RebarTheme.CreateMenuItemRenderer Overload List