Click here to Skip to main content
15,889,838 members
Articles / Desktop Programming / Windows Forms

ButtonBar Control using .NET

Rate me:
Please Sign up or sign in to vote.
4.95/5 (43 votes)
3 Dec 2009CPOL5 min read 64.7K   5.5K   104  
Themed ButtonBar control supporting custom draw with full Designer support
using System;
using System.Drawing;
using ButtonBarsControl.Control;
using ButtonBarsControl.Design.Layout;
using ButtonBarsControl.Design.Utility;

namespace ButtonBarsControl.Design.Entity
{
    /// <summary>
    /// Class holding information related to <see cref="ButtonBar.CustomDrawBackGround"/> event.
    /// </summary>
    public class DrawBackGroundEventArgs : EventArgs
    {
        /// <summary>
        /// Initializes a new instance of <see cref="DrawBackGroundEventArgs"/> with supplied arguments.
        /// </summary>
        /// <param name="graphics">Graphics surface where drawing has to be done.</param>
        /// <param name="bounds"><see cref="ButtonBar"/> control's boundry.</param>
        /// <param name="appearance">Appearance of current <see cref="ButtonBar"/></param>
        /// <param name="bar">Related <see cref="ButtonBar"/></param>
        public DrawBackGroundEventArgs(Graphics graphics, Rectangle bounds, AppearanceBar appearance, ButtonBar bar)
        {
            Graphics = graphics;
            Bounds = bounds;
            Appearance = appearance;
            Bar = bar;
        }

        /// <summary>
        /// Gets or sets drwaing has been done by user or not.
        /// </summary>
        public bool Handeled { get; set; }

        /// <summary>
        /// Gets Graphics surface where drawing has to be done.
        /// </summary>
        public Graphics Graphics { get; private set; }

        /// <summary>
        /// Gets <see cref="ButtonBar"/> control's boundry.
        /// </summary>
        public Rectangle Bounds { get; private set; }

        /// <summary>
        /// Gets appearance of current <see cref="ButtonBar"/>
        /// </summary>
        public AppearanceBar Appearance { get; private set; }

        /// <summary>
        /// Gets related <see cref="ButtonBar"/>
        /// </summary>
        public ButtonBar Bar { get; private set; }

        /// <summary>
        /// Draw control background.
        /// </summary>
        public void DrawBackground()
        {
            PaintUtility.DrawBackground(Graphics, Bounds, Appearance.BackStyle.GetBrush(Bounds),
                                        Appearance.AppearanceBorder.CornerShape, Appearance.CornerRadius, null);
        }

        /// <summary>
        /// Draw control border.
        /// </summary>
        public void DrawBorder()
        {
            if (!Bar.ShowBorders) return;
            var rect = new Rectangle(Bounds.X, Bounds.Y, Bounds.Width - 1, Bounds.Height - 1);
            PaintUtility.DrawBorder(Graphics, rect, Appearance.AppearanceBorder.CornerShape,
                                    Appearance.AppearanceBorder.BorderVisibility,
                                    Appearance.AppearanceBorder.BorderLineStyle, Appearance.CornerRadius,
                                    Bar.Focused ? Appearance.FocusedBorder : Appearance.NormalBorder, null, null);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions