예제 #1
0
            /// <summary>
            /// Handles the <see cref="E:CustomDrawItems" /> event.
            /// </summary>
            /// <param name="sender">The sender.</param>
            /// <param name="e">The <see cref="DrawItemsEventArgs"/> instance containing the event data.</param>
            private void OnCustomDrawItems(object sender, DrawItemsEventArgs e)
            {
                var o  = (AppearanceItem)pgrdItem.SelectedObject;
                var ts = o.AppearenceText.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.AppearenceText : o.AppearenceText;

                switch (int.Parse(e.Item.Tag.ToString()))
                {
                case 1:
                    PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                        o.DisabledStyle.IsEmpty
                                                                ? ZeroitToxicButton.DEFAULT.Item.DisabledStyle
                                                                : o.DisabledStyle);
                    PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                             o.DisabledBorder.IsEmpty
                                                     ? ZeroitToxicButton.DEFAULT.Item.DisabledBorder
                                                     : o.DisabledBorder);
                    PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                            o.DisabledForeGround.IsEmpty
                                                    ? ZeroitToxicButton.DEFAULT.Item.DisabledForeGround
                                                    : o.DisabledForeGround);
                    break;

                case 2:
                    PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                        o.SelectedStyle.IsEmpty
                                                                ? ZeroitToxicButton.DEFAULT.Item.SelectedStyle
                                                                : o.SelectedStyle);
                    PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                             o.SelectedBorder.IsEmpty
                                                     ? ZeroitToxicButton.DEFAULT.Item.SelectedBorder
                                                     : o.SelectedBorder);
                    PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                            o.SelectedForeGround.IsEmpty
                                                    ? ZeroitToxicButton.DEFAULT.Item.SelectedForeGround
                                                    : o.SelectedForeGround);
                    break;

                case 3:
                    PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                        o.ClickStyle.IsEmpty
                                                                ? ZeroitToxicButton.DEFAULT.Item.ClickStyle
                                                                : o.ClickStyle);
                    PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                             o.SelectedBorder.IsEmpty
                                                     ? ZeroitToxicButton.DEFAULT.Item.SelectedBorder
                                                     : o.SelectedBorder);
                    PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                            o.SelectedForeGround.IsEmpty
                                                    ? ZeroitToxicButton.DEFAULT.Item.SelectedForeGround
                                                    : o.SelectedForeGround);
                    break;

                case 4:
                    PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                        o.HoverStyle.IsEmpty
                                                                ? ZeroitToxicButton.DEFAULT.Item.HoverStyle
                                                                : o.HoverStyle);
                    PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                             o.HoverBorder.IsEmpty
                                                     ? ZeroitToxicButton.DEFAULT.Item.HoverBorder
                                                     : o.HoverBorder);
                    PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                            o.HoverForeGround.IsEmpty
                                                    ? ZeroitToxicButton.DEFAULT.Item.HoverForeGround
                                                    : o.HoverForeGround);
                    break;

                case 5:
                    PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                        o.SelectedHoverStyle.IsEmpty
                                                                ? ZeroitToxicButton.DEFAULT.Item.SelectedHoverStyle
                                                                : o.SelectedHoverStyle);
                    PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                             o.HoverBorder.IsEmpty
                                                     ? ZeroitToxicButton.DEFAULT.Item.HoverBorder
                                                     : o.HoverBorder);
                    PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                            o.HoverForeGround.IsEmpty
                                                    ? ZeroitToxicButton.DEFAULT.Item.HoverForeGround
                                                    : o.HoverForeGround);
                    break;

                default:
                    PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds,
                                                        o.BackStyle.IsEmpty
                                                                ? ZeroitToxicButton.DEFAULT.Item.BackStyle
                                                                : o.BackStyle);
                    PaintUtility.PaintBorder(e.Graphics, e.Bounds,
                                             o.NormalBorder.IsEmpty
                                                     ? ZeroitToxicButton.DEFAULT.Item.NormalBorder
                                                     : o.NormalBorder);
                    PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false,
                                            o.NormalForeGround.IsEmpty
                                                    ? ZeroitToxicButton.DEFAULT.Item.NormalForeGround
                                                    : o.NormalForeGround);
                    break;
                }
                e.Handeled = true;
            }
예제 #2
0
        /// <summary>
        /// Draw Caption of <see cref="BarItem" />
        /// </summary>
        public void DrawItemText()
        {
            ImageAlignment alignment = Item.ImageAlignment == ItemImageAlignment.Inherit
                                           ? Bar.ImageAlignment
                                           : ((ImageAlignment)((int)Item.ImageAlignment));
            var b        = new Rectangle(Bounds.Location, Bounds.Size);
            var iconSize = Size.Empty;

            if (Bar.ImageList != null && Item.ImageIndex >= 0 && Item.ImageIndex < Bar.ImageList.Images.Count)
            {
                iconSize = Bar.ImageList.ImageSize;
            }
            int iW = (!iconSize.IsEmpty && (alignment == ImageAlignment.Left || alignment == ImageAlignment.Right)
                          ? iconSize.Width
                          : 0);
            int iH = (!iconSize.IsEmpty && (alignment == ImageAlignment.Bottom || alignment == ImageAlignment.Top)
                          ? iconSize.Height
                          : 0);

            var textRect = new Rectangle(0, 0,
                                         Bounds.Width - iW - 1, Bounds.Height - iH - 2);

            if (alignment == ImageAlignment.Top || alignment == ImageAlignment.Bottom)
            {
                textRect.X = b.X;
            }
            else if (alignment == ImageAlignment.Left)
            {
                textRect.X = b.X + iW;
            }
            else
            {
                textRect.X = Bounds.X;
            }

            if (alignment == ImageAlignment.Bottom || alignment == ImageAlignment.Right)
            {
                textRect.Y = b.Y;
            }
            else if (alignment == ImageAlignment.Top)
            {
                textRect.Y = b.Y + iH;
            }
            else if (alignment == ImageAlignment.Left)
            {
                textRect.Y = b.Y;
            }


            string itemText = Item.Caption;
            var    c        = Color.Empty;

            switch (State)
            {
            case State.Selected:
                c = Item.Appearance.SelectedForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.SelectedForeGround
                            : Item.Appearance.SelectedForeGround;
                break;

            case State.Disabled:
                c = Item.Appearance.DisabledForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.DisabledForeGround
                            : Item.Appearance.DisabledForeGround;
                break;

            case State.Hover:
                c = Item.Appearance.HoverForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.HoverForeGround
                            : Item.Appearance.HoverForeGround;
                break;

            case State.SelectedHover:
                c = Item.Appearance.HoverForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.HoverForeGround
                            : Item.Appearance.HoverForeGround;
                break;

            case State.Normal:
                c = Item.Appearance.NormalForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.NormalForeGround
                            : Item.Appearance.NormalForeGround;
                break;

            case State.Pressed:
                c = Item.Appearance.SelectedForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.SelectedForeGround
                            : Item.Appearance.SelectedForeGround;
                break;
            }
            PaintUtility.DrawString(Graphics, textRect, itemText,
                                    Item.Appearance.AppearenceText.IsEmpty
                                        ? Bar.CurrentAppearance.Item.AppearenceText
                                        : Item.Appearance.AppearenceText, Bar.UseMnemonic, c);
        }