コード例 #1
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            bool pressed     = this.IsPressed;
            bool highlighted = this.IsHover;

            highlighted |= (this.UseButtonBorder == false && this.IsFocused == true);

            Rectangle backgroundRect  = this.ClientRectangle;
            Color     backgroundColor = highlighted ? this.HighlightColor : this.BackColor;
            Color     borderColor     = this.IsFocused == true ? this.AccentColor : this.TextColor;
            Color     labelColor      = this.TextColor;

            if (pressed == true)
            {
                backgroundColor = this.PressColor;
            }

            if (this.Enabled == false)
            {
                borderColor = labelColor = DisabledTextColor;
            }

            using (SolidBrush brush = new SolidBrush(backgroundColor))
            {
                pevent.Graphics.FillRectangle(brush, backgroundRect);
            }

            SmoothingMode lastSmoothingMode = pevent.Graphics.SmoothingMode;

            pevent.Graphics.SmoothingMode = SmoothingMode.None;

            if (this.UseButtonBorder == true)
            {
                using (Pen pen = new Pen(borderColor, 2))
                {
                    pen.Alignment = PenAlignment.Inset;
                    pevent.Graphics.DrawRectangle(pen, backgroundRect);
                }
            }

            pevent.Graphics.SmoothingMode = lastSmoothingMode;

            TextRenderer.DrawText(
                pevent.Graphics,
                this.Text,
                this.Font,
                this.textRect,
                labelColor,
                this.textFormat);

            DrawingUtils.DrawIcon(
                pevent.Graphics,
                this.iconRect,
                this.Icon,
                this.Enabled == true ? IconMultiplyColor : DisabledTextColor);
        }
コード例 #2
0
        public virtual void UpdateLayout()
        {
            textFormat = TextFormatFlags.TextBoxControl
                         | TextFormatFlags.EndEllipsis
                         | TextFormatFlags.WordBreak;

            textFormat |= DrawingUtils.ContentAlignmentToTextFormatFlags(labelAlignment);

            if (Multiline == true)
            {
                textFormat &= ~TextFormatFlags.SingleLine;
            }
            else
            {
                textFormat |= TextFormatFlags.SingleLine;
            }

            this.Invalidate();
        }
コード例 #3
0
        protected virtual void UpdateLayout()
        {
            this.iconRect = this.IconRect;
            this.textRect = this.TextRect;

            textFormat = DrawingUtils.ContentAlignmentToTextFormatFlags(TextAlignment);

            textFormat |= TextFormatFlags.TextBoxControl
                          | TextFormatFlags.WordBreak
                          | TextFormatFlags.EndEllipsis;

            if (Multiline)
            {
                textFormat |= TextFormatFlags.WordBreak;
                textFormat &= ~TextFormatFlags.SingleLine;
            }
            else
            {
                textFormat |= TextFormatFlags.SingleLine;
                textFormat &= ~TextFormatFlags.WordBreak;
            }

            this.Invalidate();
        }
コード例 #4
0
 protected override void OnPaintBackground(PaintEventArgs pevent)
 {
     DrawingUtils.FillRectangle(pevent.Graphics, this.BackColor, pevent.ClipRectangle);
 }
コード例 #5
0
        protected virtual void UpdateLayout()
        {
            Rectangle viewRect    = this.ClientRectangle;
            Padding   viewPadding = this.Padding;

            Rectangle labelRect;
            Rectangle checkBackRect;
            Rectangle checkRect;

            int checkWidth  = this.CheckmarkWidth;
            int checkHeight = this.CheckmarkHeight;
            int checkOffset = 5;

            checkBackRect = new Rectangle();

            switch (CheckmarkAlignment)
            {
            case VerticalAlignment.Top:
                checkBackRect.X = viewRect.Left + viewPadding.Left;
                checkBackRect.Y = viewRect.Top + viewPadding.Top;
                break;

            case VerticalAlignment.Middle:
                checkBackRect.X = viewRect.Left + viewPadding.Left;
                checkBackRect.Y = viewPadding.Top + (viewRect.Height - viewPadding.Vertical - checkHeight) / 2;
                break;

            case VerticalAlignment.Bottom:
                checkBackRect.X = viewRect.Left + viewPadding.Left;
                checkBackRect.Y = viewRect.Bottom - viewPadding.Bottom - checkHeight;
                break;
            }

            switch (Style)
            {
            case CheckmarkStyle.Checkmark:
                checkBackRect.Width = checkBackRect.Height = checkHeight;
                checkRect           = checkBackRect;
                checkRect.Width     = checkRect.Height -= checkOffset * 2;
                checkRect.X        += checkOffset;
                checkRect.Y        += checkOffset;
                this.CheckmarkIcon  = VectorIcons.Checkmark(checkRect);
                break;

            case CheckmarkStyle.Square:
                checkBackRect.Width = checkBackRect.Height = checkHeight;
                checkRect           = checkBackRect;
                checkRect.Width     = checkRect.Height -= checkOffset * 2;
                checkRect.X        += checkOffset;
                checkRect.Y        += checkOffset;
                break;

            case CheckmarkStyle.Toggle:
                checkBackRect.Width  = checkWidth;
                checkBackRect.Height = checkHeight;
                checkRect            = checkBackRect;
                checkRect.Width     -= checkOffset * 2;
                checkRect.Width     /= 2;
                checkRect.Height    -= checkOffset * 2;
                checkRect.X         += checkOffset;
                checkRect.Y         += checkOffset;

                if (Checked == true)
                {
                    checkRect.X += checkRect.Width;
                }
                break;

            default:
                checkBackRect.Width  = checkWidth;
                checkBackRect.Height = checkHeight;
                checkRect            = checkBackRect;
                break;
            }

            labelRect = new Rectangle(
                viewRect.Left + viewPadding.Left + checkBackRect.Width + TextOffset,
                viewRect.Top + viewPadding.Top,
                viewRect.Width - viewPadding.Horizontal - checkBackRect.Width - TextOffset,
                viewRect.Height - viewPadding.Vertical);

            TextRect          = labelRect;
            CheckmarkBackRect = checkBackRect;
            CheckmarkRect     = checkRect;

            textFormat = DrawingUtils.ContentAlignmentToTextFormatFlags(TextAlignment);

            textFormat |= TextFormatFlags.TextBoxControl
                          | TextFormatFlags.WordBreak
                          | TextFormatFlags.EndEllipsis;

            if (Multiline)
            {
                textFormat |= TextFormatFlags.WordBreak;
                textFormat &= ~TextFormatFlags.SingleLine;
            }
            else
            {
                textFormat |= TextFormatFlags.SingleLine;
                textFormat &= ~TextFormatFlags.WordBreak;
            }

            this.Invalidate();
        }
コード例 #6
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            if (pe.Graphics == null)
            {
                return;
            }

            TabData tab;
            int     displayedTabsCount = DisplayedTabs;
            bool    useIcon            = UseLabelIcons;
            Font    textFont           = TabsBarFont;

            Pen        outlinePen       = new Pen(Color.Black, 2);
            Color      textColor        = TabsBarTextColor;
            SolidBrush textBrush        = new SolidBrush(TabsBarTextColor);
            SolidBrush selecedtBrush    = new SolidBrush(TabViewSelectColor);
            SolidBrush accentBrush      = new SolidBrush(AccentColor);
            SolidBrush highlightedBrush = new SolidBrush(TabsBarHighlightColor);

            for (int i = 0; i < tabsData.Count; i++)
            {
                if (displayedTabsCount > -1 && i >= displayedTabsCount)
                {
                    break;
                }

                tab = tabsData[i];

                if (tab.panel != null)
                {
                    if (tab.panel == SelectedTab)
                    {
                        pe.Graphics.FillRectangle(selecedtBrush, tab.tabRect);

                        if (UseSelectionMark == true)
                        {
                            switch (TabsBarLayout)
                            {
                            case TabViewLayout.Vertical:
                                pe.Graphics.FillRectangle(accentBrush, new Rectangle(
                                                              tab.tabRect.X,
                                                              tab.tabRect.Y,
                                                              SelectionMarkSize,
                                                              tab.tabRect.Height
                                                              ));
                                break;

                            case TabViewLayout.Horizontal:
                                pe.Graphics.FillRectangle(accentBrush, new Rectangle(
                                                              tab.tabRect.X,
                                                              tab.tabRect.Y + tab.tabRect.Height - SelectionMarkSize,
                                                              tab.tabRect.Width,
                                                              SelectionMarkSize
                                                              ));
                                break;
                            }
                        }
                    }
                    else if (tab.panel == HighlightedTab)
                    {
                        pe.Graphics.FillRectangle(highlightedBrush, tab.tabRect);
                    }

                    if (useIcon == true && tab.panel.Icon != null)
                    {
                        InterpolationMode lastInterpolationMode = pe.Graphics.InterpolationMode;
                        pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;

                        pe.Graphics.DrawImage(
                            tab.panel.Icon,
                            DrawingUtils.CreateRectFromAspect(tab.iconRect, tab.panel.Icon.Size));

                        pe.Graphics.InterpolationMode = lastInterpolationMode;
                    }

                    TextRenderer.DrawText(pe.Graphics, tab.panel.Text, textFont, tab.textRect, textColor, textFormat);
                }
            }

            if (DisplayedTabs > -1)
            {
                if (allTabsButtonHighlighted == true)
                {
                    pe.Graphics.FillRectangle(highlightedBrush, allTabsButtonRect);
                }

                PixelOffsetMode oldPixelOffsetMode = pe.Graphics.PixelOffsetMode;

                pe.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
                pe.Graphics.FillPolygon(textBrush, allTabsButtonIcon);
                pe.Graphics.PixelOffsetMode = oldPixelOffsetMode;
            }

            outlinePen.Dispose();
            selecedtBrush.Dispose();
            accentBrush.Dispose();
            highlightedBrush.Dispose();
            textBrush.Dispose();
        }