public void SetDefaultHeight()
        {
            var taskbarLocation = this.MainForm.TaskbarLocation;

            Height = taskbarLocation == Native.ABEdge.Top ||
                     taskbarLocation == Native.ABEdge.Bottom
                ? (this.IsBig ? ButtonConstants.BigHorizontalHeight(taskbarLocation) : ButtonConstants.SmallHorizontalHeight(taskbarLocation))
                : (this.IsBig ? ButtonConstants.BigVerticalHeight : ButtonConstants.SmallVerticalHeight);
        }
Example #2
0
        private void DrawImageAndText(Graphics g, bool horizontal, int spaceAfterX, int spaceAfterY)
        {
            bool showLabel = ShowLabel && (this.Width > (IsBig ? ButtonConstants.WidthWithoutLabel : ButtonConstants.SmallWidthWithoutLabel));

            var taskbarLocation = this.MainForm.TaskbarLocation;

            int iconPosY = !IsBig?ButtonConstants.SmallIconPosYWithLabel(taskbarLocation) : ButtonConstants.BigIconPosYWithLabel(taskbarLocation);

            if (!horizontal)
            {
                iconPosY += 1;
            }

            bool renderImage = this.Image != null;

            #region Draw text and image
            if (showLabel)
            {
                int iconPosX = !IsBig
                    ? (showLabel ? ButtonConstants.SmallIconPosXWithLabel : ButtonConstants.SmallIconPosXWithoutLabel)
                    : (showLabel ? ButtonConstants.BigIconPosXWithLabel : ButtonConstants.BigIconPosXWithoutLabel);
                int textPosX = !IsBig ? ButtonConstants.SmallTextPosX : ButtonConstants.BigTextPosX;
                if (renderImage)
                {
                    Point location = new Point(iconPosX + (_isClicked ? ButtonConstants.ClickedOffset : 0), iconPosY + (_isClicked ? ButtonConstants.ClickedOffset : 0));
                    g.DrawImage(this.Image, location);

                    // paint overlay icon, if exists
                    if (IsBig && this._overlayIcon != null)
                    {
                        location.Offset(16, 16);
                        g.DrawIcon(this._overlayIcon, new Rectangle(location, new Size(16, 16)));
                    }
                }

                Rectangle textRect = new Rectangle(textPosX, 0, Width - (textPosX + spaceAfterX + iconPosX), Height - spaceAfterY + 2);
                if (_isClicked)
                {
                    textRect.Offset(ButtonConstants.ClickedOffset, ButtonConstants.ClickedOffset);
                }

                if (AeroDecorator.Instance.IsDwmCompositionEnabled)
                {
                    // need to find a way to use antialiasing when Aero is on
                    // this doesn't look perfect, but better.
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                }
                else
                {
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                }

                if (Native.IsThemeActive() == 0)
                {
                    Font f = this.Focused || this._isClicked ? new System.Drawing.Font(Font, FontStyle.Bold) : Font;
                    g.DrawString(Text, f, _textColor, textRect, _format);
                }
                else
                {
                    g.DrawString(Text, Font, _textColor, textRect, _format);
                }
            }
            else
            {
                if (renderImage)
                {
                    g.DrawImage(this.Image,
                                (this.Width - this.Image.Width) / 2 + (_isClicked ? ButtonConstants.ClickedOffset : 0),
                                iconPosY + (_isClicked ? ButtonConstants.ClickedOffset : 0));
                }
            }
            #endregion
        }
        /// <summary>
        /// Resize buttons to fit taskbar
        /// </summary>
        public void ArrangeButtons()
        {
            if (_taskbarButtons.Count == 0)
            {
                return;
            }

            if (FlowDirection == System.Windows.Forms.FlowDirection.LeftToRight)
            {
                // if only icon mode, buttons are already at minimum size
                if (!TaskbarPropertiesManager.Instance.Properties.ShowLabels)
                {
                    return;
                }

                // calculate space occupied by buttons and available space
                int buttonCrtWidth = _taskbarButtons[0].Width;
                int buttonsCount   = _taskbarButtons.Count;
                int pinnedWidth    = _taskbarPinnedButtons.Count > 0 ? _taskbarPinnedButtons.Sum(tpb => tpb.Visible ? tpb.Width : 0) : 0;

                int spaceForButtons = this.ClientRectangle.Width - pinnedWidth - 10;

                int min, max, minThreshold;
                ButtonConstants.GetWidthLimits(IsBig, out min, out minThreshold, out max);

                int totalWidth = buttonsCount * buttonCrtWidth;
                int width      = spaceForButtons / buttonsCount;

                if (totalWidth > spaceForButtons)
                {
                    if (width < minThreshold)
                    {
                        width = min;
                    }

                    SetButtonsMaxWidth(width);
                }
                else
                {
                    if (width < minThreshold)
                    {
                        width = min;
                    }

                    if (width > max)
                    {
                        width = max;
                    }

                    SetButtonsMaxWidth(width);
                }
            }
            else
            {
                bool isVisualTheme = Native.IsThemeActive() != 0;

                if (isVisualTheme)
                {
                    // vertical layout
                    SetButtonsMaxWidth(this.Width);
                    _taskbarButtons.ForEach(tb => tb.Width = this.Width);
                }
                else
                {
                    SetButtonsMaxWidth(this.Width - 7);
                    _taskbarButtons.ForEach(tb => tb.Width = this.Width - 7);
                }
            }
        }