/// <summary>
 /// Fires <see cref="CustomDrawItems"/> event.
 /// </summary>
 /// <param name="args">Object containing event data.</param>
 protected virtual void OnCustomDrawItems(DrawItemsEventArgs args)
 {
     if (CustomDrawItems != null)
     {
         CustomDrawItems(this, args);
     }
 }
 private void OnCustomDrawItems(object sender, DrawItemsEventArgs e)
 {
     var o = (AppearanceItem) pgrdItem.SelectedObject;
     var ts = o.AppearenceText.IsEmpty ? ButtonBar.DEFAULT.Item.AppearenceText : o.AppearenceText;
     switch (int.Parse(e.Item.Tag.ToString()))
     {
         case 1:
             PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                 o.DisabledStyle.IsEmpty
                                                     ? ButtonBar.DEFAULT.Item.DisabledStyle
                                                     : o.DisabledStyle);
             PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                      o.DisabledBorder.IsEmpty
                                          ? ButtonBar.DEFAULT.Item.DisabledBorder
                                          : o.DisabledBorder);
             PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                     o.DisabledForeGround.IsEmpty
                                         ? ButtonBar.DEFAULT.Item.DisabledForeGround
                                         : o.DisabledForeGround);
             break;
         case 2:
             PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                 o.SelectedStyle.IsEmpty
                                                     ? ButtonBar.DEFAULT.Item.SelectedStyle
                                                     : o.SelectedStyle);
             PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                      o.SelectedBorder.IsEmpty
                                          ? ButtonBar.DEFAULT.Item.SelectedBorder
                                          : o.SelectedBorder);
             PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                     o.SelectedForeGround.IsEmpty
                                         ? ButtonBar.DEFAULT.Item.SelectedForeGround
                                         : o.SelectedForeGround);
             break;
         case 3:
             PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                 o.ClickStyle.IsEmpty
                                                     ? ButtonBar.DEFAULT.Item.ClickStyle
                                                     : o.ClickStyle);
             PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                      o.SelectedBorder.IsEmpty
                                          ? ButtonBar.DEFAULT.Item.SelectedBorder
                                          : o.SelectedBorder);
             PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                     o.SelectedForeGround.IsEmpty
                                         ? ButtonBar.DEFAULT.Item.SelectedForeGround
                                         : o.SelectedForeGround);
             break;
         case 4:
             PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                 o.HoverStyle.IsEmpty
                                                     ? ButtonBar.DEFAULT.Item.HoverStyle
                                                     : o.HoverStyle);
             PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                      o.HoverBorder.IsEmpty
                                          ? ButtonBar.DEFAULT.Item.HoverBorder
                                          : o.HoverBorder);
             PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                     o.HoverForeGround.IsEmpty
                                         ? ButtonBar.DEFAULT.Item.HoverForeGround
                                         : o.HoverForeGround);
             break;
         case 5:
             PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                 o.SelectedHoverStyle.IsEmpty
                                                     ? ButtonBar.DEFAULT.Item.SelectedHoverStyle
                                                     : o.SelectedHoverStyle);
             PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                      o.HoverBorder.IsEmpty
                                          ? ButtonBar.DEFAULT.Item.HoverBorder
                                          : o.HoverBorder);
             PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                     o.HoverForeGround.IsEmpty
                                         ? ButtonBar.DEFAULT.Item.HoverForeGround
                                         : o.HoverForeGround);
             break;
         default:
             PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                 o.BackStyle.IsEmpty
                                                     ? ButtonBar.DEFAULT.Item.BackStyle
                                                     : o.BackStyle);
             PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                      o.NormalBorder.IsEmpty
                                          ? ButtonBar.DEFAULT.Item.NormalBorder
                                          : o.NormalBorder);
             PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                     o.NormalForeGround.IsEmpty
                                         ? ButtonBar.DEFAULT.Item.NormalForeGround
                                         : o.NormalForeGround);
             break;
     }
     e.Handeled = true;
 }
 /// <summary>
 /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event.
 /// </summary>
 /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data. </param>
 protected override void OnPaint(PaintEventArgs e)
 {
     CreateMemoryBitmap();
     //RefreshControl();
     Graphics.Clear(BackColor);
     //Graphics.Clear(Color.Transparent);
     var bArgs = new DrawBackGroundEventArgs(Graphics, ClientRectangle, CurrentAppearance.Bar, this);
     OnCustomDrawBackGround(bArgs);
     if (!bArgs.Handeled)
     {
         bArgs.DrawBackground();
         bArgs.DrawBorder();
     }
     if (!((items == null) || (items.Count == 0)))
     {
         foreach (BarItem barItem in items)
         {
             var itemRect = new Rectangle(Padding.Left, barItem.Top, buttonWidth - Padding.Left - Padding.Right,
                                          barItem.Height);
             itemRect.Offset(0, AutoScrollPosition.Y);
             var args = new DrawItemsEventArgs(Graphics, itemRect, barItem, GetButtonState(barItem), this);
             OnCustomDrawItems(args);
             if (args.Handeled) continue;
             args.DrawItemBackGround();
             args.DrawItemBorder();
             args.DrawIcon();
             args.DrawItemText();
         }
     }
     if (!Enabled)
         Graphics.FillRectangle(
             new SolidBrush(Color.FromArgb((int) (DisableTransparency*2.55), CurrentAppearance.Bar.DisabledMask)),
             0, 0, Width - 1, Height - 1);
     PaintUtility.DrawImage(e.Graphics, new Rectangle(0, 0, Width, Height), bmp, (int) (ImageTransparency*2.55));
 }