コード例 #1
0
        public override void SetSize(
            ListBarGroupView view,
            Font defaultFont,
            Size imageSize)
        {
            base.SetSize(view, defaultFont, imageSize);
            rectangle.Height -= 3;

            rectangle.Height = (view == ListBarGroupView.LargeIcons) ? rectangle.Height - 24 : rectangle.Height;
        }
コード例 #2
0
        /// <summary>
        /// Draws this item into the specified graphics object.
        /// </summary>
        /// <param name="gfx">The graphics object to draw onto.</param>
        /// <param name="ils">The ImageList to source icons from.</param>
        /// <param name="defaultFont">The default font to use to draw the button.</param>
        /// <param name="style">The style (Outlook version) to draw using.</param>
        /// <param name="view">The view (large or small icons) to draw using.</param>
        /// <param name="scrollOffset">The offset of the first item from the
        /// (0,0) point in the graphics object.</param>
        /// <param name="skipDrawText">Whether to skip drawing text or not
        /// (the item is being edited)</param>
        /// <param name="controlEnabled">Whether the control is enabled or not.</param>
        public override void DrawButton(
            Graphics gfx,
            ImageList ils,
            Font defaultFont,
            ListBarDrawStyle style,
            ListBarGroupView view,
            int scrollOffset,
            bool controlEnabled,
            bool skipDrawText
            )
        {
            bool rightToLeft = false;
            Font drawFont    = Font;

            if (drawFont == null)
            {
                drawFont = defaultFont;
            }
            Color backColor = Color.FromKnownColor(KnownColor.Control);

            if (Owner != null)
            {
                if (Owner.RightToLeft == RightToLeft.Yes)
                {
                    rightToLeft = true;
                }
                backColor = Owner.BackColor;
            }

            Rectangle drawRect = new Rectangle(Location,
                                               new Size(Width, Height));

            drawRect.Offset(0, scrollOffset);
            if (((Selected) && (!MouseOver)) || (MouseOver && MouseDown))
            {
                // Draw the background:
                VSNetListBarUtility.DrawSelectedItemBackground(gfx, drawRect);
            }

            Rectangle itemRect = drawRect;

            itemRect.Inflate(-1, -1);

            if ((Selected) || (MouseDown && MouseOver))
            {
                itemRect.Offset(1, 1);
            }

            RectangleF textRect;

            // Draw the icon:
            if (rightToLeft)
            {
                iconRectangle = new Rectangle(
                    itemRect.Right - ils.ImageSize.Width - 4,
                    itemRect.Top + (itemRect.Height - ils.ImageSize.Height) / 2,
                    ils.ImageSize.Width, ils.ImageSize.Height);
                textRect = new RectangleF(
                    itemRect.Left, itemRect.Top,
                    itemRect.Width - (ils.ImageSize.Width - 6),
                    itemRect.Height);
            }
            else
            {
                iconRectangle = new Rectangle(
                    itemRect.Left + 4,
                    itemRect.Top + (itemRect.Height - ils.ImageSize.Height) / 2,
                    ils.ImageSize.Width, ils.ImageSize.Height);
                textRect = new RectangleF(
                    itemRect.Left + ils.ImageSize.Height + 6, itemRect.Top,
                    itemRect.Width - (ils.ImageSize.Width - 6),
                    itemRect.Height);
            }
            if (IconIndex <= ils.Images.Count)
            {
                if (Enabled && controlEnabled)
                {
                    ils.Draw(gfx, iconRectangle.Left, iconRectangle.Top,
                             IconIndex);
                }
                else
                {
                    System.Windows.Forms.ControlPaint.DrawImageDisabled(gfx, ils.Images[IconIndex],
                                                                        iconRectangle.Left, iconRectangle.Top, backColor);
                }
            }

            if ((view == ListBarGroupView.SmallIconsOnly) || (view == ListBarGroupView.LargeIconsOnly))
            {
                textRectangle = new Rectangle(0, 0, 0, 0);
                skipDrawText  = true;
            }

            if (!skipDrawText)
            {
                // Draw the text:
                StringFormat format = new StringFormat(StringFormatFlags.LineLimit |
                                                       (rightToLeft ? StringFormatFlags.DirectionRightToLeft : 0));
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Center;
                format.Trimming      = StringTrimming.EllipsisWord;
                if (Enabled && controlEnabled)
                {
                    Brush br = new SolidBrush(ForeColor);
                    gfx.DrawString(Caption, drawFont, br, textRect, format);
                    br.Dispose();
                }
                else
                {
                    Brush br = new SolidBrush(CustomBorderColor.ColorLightLight(backColor));
                    textRect.Offset(1F, 1F);
                    gfx.DrawString(Caption, drawFont, br, textRect, format);
                    br.Dispose();
                    textRect.Offset(-1F, -1F);
                    br = new SolidBrush(CustomBorderColor.ColorDark(backColor));
                    gfx.DrawString(Caption, drawFont, br, textRect, format);
                    br.Dispose();
                }
                format.Dispose();

                textRectangle = new Rectangle((int)textRect.Left, (int)textRect.Top,
                                              (int)textRect.Width, (int)textRect.Height);

                // TODO_ If mouse over and text too wide show the popup.
                // Currently a problem with my popup code in that it
                // foils the Framework's WM_NCACTIVATE processing which
                // results in spurious focus/mouse over events...
            }


            // Draw the border:
            if (((MouseOver) || (Selected)) && (Enabled))
            {
                CustomBorderColor.DrawBorder(gfx, drawRect,
                                             backColor, true,
                                             ((MouseDown && MouseOver) || (Selected)));
            }
        }