示例#1
0
        internal void RenderButton(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color arrowColor,
            ArrowDirection direction)
        {
            CornerRadius cr = new CornerRadius();

            switch (direction)
            {
            case ArrowDirection.Left:
                cr = new CornerRadius(2, 0, 2, 0);
                break;

            case ArrowDirection.Right:
                cr = new CornerRadius(0, 2, 0, 2);
                break;
            }

            RoundRectangle roundRect = new RoundRectangle(rect, cr);

            GDIHelper.FillPath(g, roundRect, baseColor, baseColor);
            GDIHelper.DrawPathBorder(g, roundRect);
            using (SolidBrush brush = new SolidBrush(arrowColor))
            {
                RenderArrowInternal(
                    g,
                    rect,
                    direction,
                    brush);
            }
        }
示例#2
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            base.OnDrawSubItem(e);
            if (View != View.Details || e.ItemIndex == -1)
            {
                return;
            }

            Rectangle          bounds    = e.Bounds;
            ListViewItemStates itemState = e.ItemState;
            Graphics           g         = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Blend blen = new Blend();

            blen.Positions = new float[] { 0f, 0.4f, 0.7f, 1f };
            blen.Factors   = new float[] { 0f, 0.3f, 0.8f, 0.2f };
            Color c1, c2;

            if ((itemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
            {
                c1 = this._SelectedBeginColor;
                c2 = this._SelectedEndColor;
                //使用全局皮肤色彩,注意选择文字需要反色处理
                c1             = SkinManager.CurrentSkin.HeightLightControlColor.First;
                c2             = SkinManager.CurrentSkin.HeightLightControlColor.Second;
                blen.Factors   = SkinManager.CurrentSkin.HeightLightControlColor.Factors;
                blen.Positions = SkinManager.CurrentSkin.HeightLightControlColor.Positions;
                GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), c1, c2, blen);
            }
            else
            {
                if (e.ColumnIndex == 0)
                {
                    bounds.Inflate(0, -1);
                }
                c1 = e.ItemIndex % 2 == 0 ? this._RowBackColor1 : this._RowBackColor2;
                c2 = c1;
                GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), c1, c2, blen);
            }

            if (e.ColumnIndex == 0)
            {
                this.OnDrawFirstSubItem(e, g);
            }
            else
            {
                this.DrawNormalSubItem(e, g);
            }
        }
示例#3
0
        private void DrawBorder(Graphics g)
        {
            GDIHelper.InitializeGraphics(g);
            Rectangle      rect      = new Rectangle(1, 1, this.Width - 3, this.Height - 3);
            RoundRectangle roundRect = new RoundRectangle(rect, this._CornerRadius);
            Color          c         = (!this._TextBox.Enabled || this._TextBox.ReadOnly) ? Color.FromArgb(215, 250, 243) : Color.White;

            this._TextBox.BackColor = c;
            //this._TextBox.Font = this._Font;
            //this._TextBox.ForeColor = this._ForeColor;
            GDIHelper.FillPath(g, roundRect, c, c);
            GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor);
            if (this._ControlState == EnumControlState.HeightLight)
            {
                GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.Second);
                GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First);
            }
        }
示例#4
0
        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            base.OnDrawColumnHeader(e);
            Graphics g = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Rectangle bounds = e.Bounds;

            GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), this._HeaderBeginColor, this._HeaderEndColor);
            bounds.Height--;
            if (this.BorderStyle != BorderStyle.None)
            {
                using (Pen p = new Pen(this.BorderColor))
                {
                    g.DrawLine(p, new Point(bounds.Right, bounds.Bottom), new Point(bounds.Right, bounds.Top));
                    g.DrawLine(p, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Bottom));
                }
            }
            else
            {
                GDIHelper.DrawPathBorder(g, new RoundRectangle(bounds, 0), this._BorderColor);
            }

            bounds.Height++;
            TextFormatFlags flags    = GetFormatFlags(e.Header.TextAlign);
            Rectangle       textRect = new Rectangle(
                bounds.X + 3,
                bounds.Y,
                bounds.Width - 6,
                bounds.Height);;
            Image     image     = null;
            Size      imgSize   = new System.Drawing.Size(16, 16);
            Rectangle imageRect = Rectangle.Empty;

            if (e.Header.ImageList != null)
            {
                image = e.Header.ImageIndex == -1 ?
                        null : e.Header.ImageList.Images[e.Header.ImageIndex];
            }

            GDIHelper.DrawImageAndString(g, bounds, image, imgSize, e.Header.Text, this._Font, e.ForeColor);
        }
示例#5
0
        protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
        {
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  g         = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Rectangle rect = e.AffectedBounds;

            rect.Width -= 1; rect.Height -= 1;
            if (toolStrip is ToolStripDropDown)
            {
                rect.Width = this._OffsetMargin;
                Color          c = this.MenuImageMarginBackColor;
                CornerRadius   toolStripCornerRadius = new CornerRadius(this.MenuCornerRadius);
                RoundRectangle roundRect             = new RoundRectangle(rect, toolStripCornerRadius);
                GDIHelper.FillPath(g, new RoundRectangle(rect, new CornerRadius(this.MenuCornerRadius, 0, this.MenuCornerRadius, 0)), c, c);
                Image img = this.MenuImageBackImage;
                if (img != null && this.ShowMenuBackImage)
                {
                    ImageAttributes imgAttributes = new ImageAttributes();
                    GDIHelper.SetImageOpacity(imgAttributes, this.MenuImageBackImageOpacity);
                    g.DrawImage(Properties.Resources.logo_mini, new Rectangle(rect.X + 1, rect.Y + 2, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttributes);
                }

                ////绘制间隔线
                Point p1, p2;
                p1 = new Point(rect.X + this._OffsetMargin, rect.Y + 3);
                p2 = new Point(rect.X + this._OffsetMargin, rect.Bottom - 3);
                using (Pen pen = new Pen(SkinManager.CurrentSkin.BorderColor))
                {
                    g.DrawLine(pen, p1, p2);
                }
            }
            else
            {
                base.OnRenderImageMargin(e);
            }
        }
示例#6
0
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  g         = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Rectangle      rect = e.AffectedBounds;
            CornerRadius   toolStripCornerRadius = new CornerRadius(this.MenuCornerRadius);
            RoundRectangle roundRect             = new RoundRectangle(rect, toolStripCornerRadius);

            if (toolStrip is ToolStripDropDown || toolStrip is ContextMenuStrip)
            {
                this.CreateToolStripRegion(toolStrip, roundRect);
                GDIHelper.FillPath(g, roundRect, this.BackColor, this.BackColor);
            }
            else if (toolStrip is TXMenuStrip)
            {
                TXMenuStrip ms = toolStrip as TXMenuStrip;
                Color       c1 = ms.BeginBackColor;
                Color       c2 = ms.EndBackColor;
                GDIHelper.FillPath(g, new RoundRectangle(rect, new CornerRadius(0)), c1, c2);
            }
            else if (toolStrip is TXToolStrip)
            {
                rect.Inflate(1, 1);
                TXToolStrip ts = toolStrip as TXToolStrip;
                Color       c1 = ts.BeginBackColor;
                Color       c2 = ts.EndBackColor;
                GDIHelper.FillPath(g, new RoundRectangle(rect, new CornerRadius(0)), c1, c2);
            }
            else if (toolStrip is TXStatusStrip)
            {
                TXStatusStrip ss = toolStrip as TXStatusStrip;
                Color         c1 = ss.BeginBackColor;
                Color         c2 = ss.EndBackColor;
                GDIHelper.FillPath(g, new RoundRectangle(rect, new CornerRadius(0)), c1, c2);
            }
        }
示例#7
0
 protected override void WndProc(ref Message m)
 {
     base.WndProc(ref m);
     switch (m.Msg)
     {
     case (int)WindowMessages.WM_PAINT:
     case (int)WindowMessages.WM_WINDOWPOSCHANGED:
         IntPtr hdc = Win32.GetDC(m.HWnd);
         try
         {
             using (Graphics g = Graphics.FromHdc(hdc))
             {
                 Rectangle bounds = _owner.HeaderEndRect();
                 GDIHelper.InitializeGraphics(g);
                 GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), this._owner._HeaderBeginColor, this._owner._HeaderEndColor);
                 bounds.Width--; bounds.Height--;
                 if (this._owner.BorderStyle != BorderStyle.None)
                 {
                     using (Pen p = new Pen(this._owner.BorderColor))
                     {
                         g.DrawLine(p, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Left, bounds.Top));
                         g.DrawLine(p, new Point(bounds.Right, bounds.Bottom), new Point(bounds.Right, bounds.Top));
                         g.DrawLine(p, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Bottom));
                     }
                 }
                 else
                 {
                     GDIHelper.DrawPathBorder(g, new RoundRectangle(bounds, 0), this._owner._BorderColor);
                 }
             }
         }
         finally
         {
             Win32.ReleaseDC(m.HWnd, hdc);
         }
         break;
     }
 }
示例#8
0
        private void DrawTabPages(Graphics g)
        {
            Rectangle tabRect;
            Point     cusorPoint = PointToClient(MousePosition);
            bool      hover;
            bool      selected;
            bool      hasSetClip      = false;
            bool      alignHorizontal =
                (Alignment == TabAlignment.Top ||
                 Alignment == TabAlignment.Bottom);
            LinearGradientMode mode = alignHorizontal ?
                                      LinearGradientMode.Vertical : LinearGradientMode.Horizontal;

            if (alignHorizontal)
            {
                IntPtr upDownButtonHandle = UpDownButtonHandle;
                bool   hasUpDown          = upDownButtonHandle != IntPtr.Zero;
                if (hasUpDown)
                {
                    if (Win32.IsWindowVisible(upDownButtonHandle))
                    {
                        RECT upDownButtonRect = new RECT();
                        Win32.GetWindowRect(
                            upDownButtonHandle, ref upDownButtonRect);
                        Rectangle upDownRect = Rectangle.FromLTRB(
                            upDownButtonRect.left,
                            upDownButtonRect.top,
                            upDownButtonRect.right,
                            upDownButtonRect.bottom);
                        upDownRect = RectangleToClient(upDownRect);

                        switch (Alignment)
                        {
                        case TabAlignment.Top:
                            upDownRect.Y = 0;
                            break;

                        case TabAlignment.Bottom:
                            upDownRect.Y =
                                ClientRectangle.Height - DisplayRectangle.Height;
                            break;
                        }
                        upDownRect.Height = ClientRectangle.Height;
                        g.SetClip(upDownRect, CombineMode.Exclude);
                        hasSetClip = true;
                    }
                }
            }

            for (int index = 0; index < base.TabCount; index++)
            {
                TabPage page = TabPages[index];
                tabRect  = GetTabRect(index);
                hover    = tabRect.Contains(cusorPoint);
                selected = SelectedIndex == index;
                Color baseColor   = _BaseTabolor;
                Color borderColor = _BorderColor;
                Blend blend       = new Blend();
                blend.Positions = new float[] { 0f, 0.3f, 0.5f, 0.7f, 1.0f };
                blend.Factors   = new float[] { 0.1f, 0.3f, 0.5f, 0.8f, 1.0f };
                if (selected)
                {
                    baseColor = this._CheckedTabColor;
                }
                else if (hover)
                {
                    baseColor       = this._HeightLightTabColor;
                    blend.Positions = new float[] { 0f, 0.3f, 0.6f, 0.8f, 1f };
                    blend.Factors   = new float[] { .2f, 0.4f, 0.6f, 0.5f, .4f };
                }
                Rectangle exRect = new Rectangle(tabRect.Left, tabRect.Bottom, tabRect.Width, 1);
                g.SetClip(exRect, CombineMode.Exclude);
                CornerRadius cr = new CornerRadius(this._TabCornerRadius, this._TabCornerRadius, 0, 0);
                tabRect.X += this._TabMargin; tabRect.Width -= this._TabMargin;
                tabRect.Y++;
                tabRect.Height--;
                RoundRectangle roundRect = new RoundRectangle(tabRect, cr);
                GDIHelper.InitializeGraphics(g);
                switch (this._TabStyle)
                {
                case EnumTabStyle.AnglesWing:
                    cr         = new CornerRadius(this._TabCornerRadius);
                    tabRect.X += this._TabCornerRadius; tabRect.Width -= this._TabCornerRadius * 2;
                    roundRect  = new RoundRectangle(tabRect, cr);
                    using (GraphicsPath path = roundRect.ToGraphicsAnglesWingPath())
                    {
                        using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, baseColor, this._BackColor, LinearGradientMode.Vertical))
                        {
                            brush.Blend = blend;
                            g.FillPath(brush, path);
                        }
                    }
                    using (GraphicsPath path = roundRect.ToGraphicsAnglesWingPath())
                    {
                        using (Pen pen = new Pen(this._BorderColor, 1))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                    break;

                case EnumTabStyle.Default:
                    GDIHelper.FillPath(g, roundRect, baseColor, this._BackColor, blend);
                    GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor);
                    break;
                }

                g.ResetClip();
                if (this.Alignment == TabAlignment.Top)
                {
                    Image img     = null;
                    Size  imgSize = Size.Empty;
                    if (this.ImageList != null && page.ImageIndex >= 0)
                    {
                        img     = this.ImageList.Images[page.ImageIndex];
                        imgSize = img.Size;
                    }

                    GDIHelper.DrawImageAndString(g, tabRect, img, imgSize, page.Text, this._CaptionFont, this._CaptionForceColor);
                }
                else
                {
                    bool hasImage = DrawTabImage(g, page, tabRect);
                    DrawtabText(g, page, tabRect, hasImage);
                }
            }
            if (hasSetClip)
            {
                g.ResetClip();
            }
        }
示例#9
0
        protected virtual void OnPaintUpDownButton(
            UpDownButtonPaintEventArgs e)
        {
            Graphics  g    = e.Graphics;
            Rectangle rect = e.ClipRectangle;

            Color upButtonBaseColor   = SkinManager.CurrentSkin.DefaultControlColor.First;
            Color upButtonBorderColor = this._BorderColor;
            Color upButtonArrowColor  = Color.Green;

            Color downButtonBaseColor   = SkinManager.CurrentSkin.DefaultControlColor.First;
            Color downButtonBorderColor = this._BorderColor;
            Color downButtonArrowColor  = Color.Green;

            Rectangle upButtonRect = rect;

            upButtonRect.X      += 2;
            upButtonRect.Y      += 2;
            upButtonRect.Width   = rect.Width / 2 - 4;
            upButtonRect.Height -= 4;

            Rectangle downButtonRect = rect;

            downButtonRect.X       = upButtonRect.Right;
            downButtonRect.Y      += 2;
            downButtonRect.Width   = rect.Width / 2 - 4;
            downButtonRect.Height -= 4;

            if (Enabled)
            {
                if (e.MouseOver)
                {
                    if (e.MousePress)
                    {
                        if (e.MouseInUpButton)
                        {
                            upButtonBaseColor = SkinManager.CurrentSkin.HeightLightControlColor.First;
                        }
                        else
                        {
                            downButtonBaseColor = SkinManager.CurrentSkin.HeightLightControlColor.First;
                        }
                    }
                    else
                    {
                        if (e.MouseInUpButton)
                        {
                            upButtonBaseColor = SkinManager.CurrentSkin.DefaultControlColor.First;
                        }
                        else
                        {
                            downButtonBaseColor = SkinManager.CurrentSkin.DefaultControlColor.First;
                        }
                    }
                }
            }
            else
            {
                upButtonBaseColor     = SystemColors.Control;
                upButtonBorderColor   = SystemColors.ControlDark;
                upButtonArrowColor    = SystemColors.ControlDark;
                downButtonBaseColor   = SystemColors.Control;
                downButtonBorderColor = SystemColors.ControlDark;
                downButtonArrowColor  = SystemColors.ControlDark;
            }

            GDIHelper.FillPath(g, new RoundRectangle(rect, new CornerRadius()), this._BackColor, this._BackColor);
            RenderButton(
                g,
                upButtonRect,
                upButtonBaseColor,
                upButtonBorderColor,
                upButtonArrowColor,
                ArrowDirection.Left);
            RenderButton(
                g,
                downButtonRect,
                downButtonBaseColor,
                downButtonBorderColor,
                downButtonArrowColor,
                ArrowDirection.Right);

            UpDownButtonPaintEventHandler handler =
                base.Events[EventPaintUpDownButton] as UpDownButtonPaintEventHandler;

            if (handler != null)
            {
                handler(this, e);
            }
        }