Ejemplo n.º 1
0
        /// <summary>
        /// Paint button background, text, and icon.
        /// </summary>
        /// <remarks>
        /// Parameter isLastLarge is passed from OnPaint() in this way:
        ///  * False if you have painted the last large button.
        ///  * True if there might be more visible large buttons to paint.
        /// </remarks>
        private void PaintButton(OutlookBarButton button, Graphics g, bool isLastLarge)
        {
            // Paint background

            ButtonState state = ButtonState.None;

            if (button.Equals(SelectedButton) || m_leftClickedButton != null)
            {
                state = ButtonState.Selected;
            }

            if (button == m_hoveringButton)
            {
                state |= ButtonState.Hovering;
            }

            if (button != m_hoveringButton && !button.Equals(SelectedButton))
            {
                state = ButtonState.Passive;
            }

            if (!button.Enabled)
            {
                state = ButtonState.Disabled;
            }

            Debug.Assert(state != ButtonState.None, "Button didn't have a definable state. Programmer error.");

            FillButton(button.Rectangle, g, state, true, button.isLarge, button.isLarge);

            // Paint icon

            Rectangle iconRect = GetRectangleForButtonIcon(button);

            if ((button.isLarge & isLastLarge) || !button.isLarge)
            {
                DrawButtonIcon(g, button, iconRect);
            }

            // Paint text

            if (button.isLarge && isLastLarge)
            {
                PointF location = new PointF();
                location.X = iconRect.X + iconRect.Width + m_buttonTextMarginFromIconOnLeft;
                location.Y = (float)button.Rectangle.Y + ((InternalButtonHeight / 2.0f) - (Font.Height / 2.0f));

                g.DrawString(button.Text, Font, GetButtonTextBrush(button == SelectedButton, button.Enabled), location);
            }
        }