Skybound Rebar

RebarBand.DrawButton Event

Occurs when a button on a band needs to be drawn.

[Visual Basic]
Public Event DrawButton As DrawButtonEventHandler
[C#]
public event DrawButtonEventHandler DrawButton;

Event Data

The event handler receives an argument of type DrawButtonEventArgs containing data related to this event. The following DrawButtonEventArgs properties provide information specific to this event.

Property Description
Button Gets the RebarButton to draw.
Graphics Gets the Graphics surface to draw the button on.
Renderer Gets a renderer that can draw the button.

Remarks

Handle this event to use your own custom code to draw one or more of the buttons on the band.

This event is not raised unless the DrawMode property is set to OwnerDraw or OwnerDrawAndMeasure.

Example

This example handles the DrawButton event of a rebar band whose DrawMode property is set to OwnerDraw. The buttons are drawn using the Microsoft Office XP style.

private void rebarBand1_DrawButton(object sender, Skybound.Rebar.DrawButtonEventArgs e)
{
    // invoke default implementation for separators:
    if (e.Renderer.ButtonType == RebarButtonType.Separator)
    {
        e.Renderer.RenderButton(e.Graphics);
    }
    else
    {
        // highlight the border and background when the button is hot or pushed
        if (e.Renderer.State != RebarButtonState.Normal || e.Renderer.Checked)
        {
            // get button bounds:
            Rectangle buttonBounds = e.Renderer.Bounds;
            // size of bounds must be reduced by 1 for DrawRectangle:
            buttonBounds.Size -= new Size(1, 1);
            
            // fill background:
            using (SolidBrush brush = new SolidBrush(Color.FromArgb(64, SystemColors.Highlight)))
                e.Graphics.FillRectangle(brush, buttonBounds);
            
            // draw border:
            e.Graphics.DrawRectangle(SystemPens.Highlight, buttonBounds);
            
            // draw menu button borders:
            if (e.Renderer.ButtonType == RebarButtonType.MenuOrPush)
            {
                Rectangle dropDown = e.Renderer.GetDropDownRectangle();
                dropDown.Size -= new Size(1, 1);
                
                e.Graphics.DrawRectangle(SystemPens.Highlight, dropDown);
            }
        }
        
        // invoke default implementation for image, text and arrow:
        e.Renderer.DrawImage(e.Graphics);
        e.Renderer.DrawText(e.Graphics);
        e.Renderer.DrawArrow(e.Graphics);
    }
}
            

See Also

RebarBand Class | Skybound.Rebar Namespace