Esempio n. 1
0
        /*
         * PRIVATE
         */
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            if (this.Width > 1 && this.Height > 1)
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                int tmpShadowOffSet = GetShadowOffSet();
                int tmpCornerRadius = GetCornerRadius();

                //Draw the Shadow
                if (DrawShadow)
                {
                    if (tmpCornerRadius > 0)
                    {
                        Rectangle    rectShadow      = new Rectangle(tmpShadowOffSet, tmpShadowOffSet, this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1);
                        GraphicsPath graphPathShadow = RichPanelHelper.GetRoundPath(rectShadow, tmpCornerRadius, this.roundCornerType);
                        using (PathGradientBrush gBrush = new PathGradientBrush(graphPathShadow))
                        {
                            gBrush.WrapMode = WrapMode.Clamp;
                            ColorBlend colorBlend = new ColorBlend(3);
                            colorBlend.Colors          = new Color[] { Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray) };
                            colorBlend.Positions       = new float[] { 0f, .1f, 1f };
                            gBrush.InterpolationColors = colorBlend;

                            e.Graphics.FillPath(gBrush, graphPathShadow);
                        }
                    }
                }

                //Draw the background
                Rectangle    rect      = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1);
                GraphicsPath graphPath = RichPanelHelper.GetRoundPath(rect, tmpCornerRadius, this.roundCornerType);
                if (this.FillStyle == RichPanelHelper.FillStyle.Gradient)
                {
                    LinearGradientBrush brush = new LinearGradientBrush(rect, this.BackgroundColor1, this.BackgroundColor2, this.GradientStyle);
                    e.Graphics.FillPath(brush, graphPath);
                }
                else if (this.FillStyle == RichPanelHelper.FillStyle.Solid)
                {
                    SolidBrush brush = new SolidBrush(this.BackgroundColor1);
                    e.Graphics.FillPath(brush, graphPath);
                }
                else
                {
                    SolidBrush brush = new SolidBrush(this.BackColor);
                    e.Graphics.FillPath(brush, graphPath);
                }

                //Draw the border
                if (DrawBorder)
                {
                    e.Graphics.DrawPath(new Pen(Color.FromArgb(180, this.borderColor), borderWidth), graphPath);
                }
            }
        }
Esempio n. 2
0
        private void PaintHeader(Graphics graphics)
        {
            if (!DrawHeader)
            {
                return;
            }

            this.headerHeight = GetHeaderHeight(graphics);

            int   tmpShadowOffSet = GetShadowOffSet();
            int   tmpCornerRadius = GetCornerRadius();
            float margin          = 3 + tmpCornerRadius / 4;

            List <float> separatorsXs = new List <float>();

            separatorsXs.Add(margin + 5);
            separatorsXs.Add(this.Width - tmpShadowOffSet - 7 - tmpCornerRadius / 4);

            //Text
            if (!string.IsNullOrEmpty(this.HeaderText))
            {
                float w = this.Width;
                if (this.headerTextAlign != RichPanelHelper.Align.Center)
                {
                    w -= tmpShadowOffSet;
                }

                SizeF size = graphics.MeasureString(this.HeaderText, this.HeaderFont);

                //Fill the header background
                if (HeaderHasBackColor)
                {
                    Rectangle    rect      = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1, headerHeight);
                    GraphicsPath graphPath = RichPanelHelper.GetRoundPath(rect, tmpCornerRadius, this.roundCornerType);

                    SolidBrush brush = new SolidBrush(this.HeaderBackColor);
                    graphics.FillPath(brush, graphPath);
                }

                //Draw the text
                float x = RichPanelHelper.GetXPos(this.HeaderTextAlign, w, size.Width, margin);
                using (Brush brush = new SolidBrush(this.HeaderTextColor))
                {
                    graphics.DrawString(this.HeaderText, this.HeaderFont, brush, x, (headerHeight - size.Height) / 2);
                }

                //Update separator position
                if (this.headerTextAlign == RichPanelHelper.Align.Left)
                {
                    separatorsXs[0] = size.Width + 15;
                }
                else if (this.headerTextAlign == RichPanelHelper.Align.Center)
                {
                    separatorsXs.Insert(1, x - 10);
                    separatorsXs.Insert(2, x + size.Width + 10);
                }
                else if (this.headerTextAlign == RichPanelHelper.Align.Right)
                {
                    separatorsXs[1] = w - size.Width - 15 - tmpCornerRadius / 4;
                }
            }

            //Image
            if (this.headerIcon != null)
            {
                float w = this.Width;
                if (this.headerIconAlign != RichPanelHelper.Align.Center)
                {
                    w -= tmpShadowOffSet;
                }

                //Draw the icon
                float x     = RichPanelHelper.GetXPos(this.HeaderIconAlign, w, this.HeaderIcon.Width, margin);
                Point point = new Point((int)x, (headerHeight - this.HeaderIcon.Height) / 2);
                graphics.DrawImage(new Bitmap(this.HeaderIcon), point);

                //Update separator position
                if (this.HeaderIconAlign == RichPanelHelper.Align.Left)
                {
                    separatorsXs[0] = x + this.headerIcon.Width + 10;
                }
                else if (this.HeaderIconAlign == RichPanelHelper.Align.Center)
                {
                    separatorsXs.Insert(1, x - 10);
                    separatorsXs.Insert(2, x + this.headerIcon.Width + 10);
                }
                else if (this.HeaderIconAlign == RichPanelHelper.Align.Right)
                {
                    separatorsXs[1] = w - this.headerIcon.Width - 10 - tmpCornerRadius / 4;
                }
            }

            //Separator
            if (this.SeparatorPos != SeparatorPosition.None)
            {
                Pen pen = new Pen(this.SeparatorColor, SeparatorWidth);
                if (this.SeparatorPos == SeparatorPosition.Bottom)
                {
                    graphics.DrawLine(pen,
                                      this.BorderWidth, headerHeight,
                                      this.Width - tmpShadowOffSet - this.BorderWidth, headerHeight);
                }
                else
                {
                    float sepY = (headerHeight - this.SeparatorWidth) / 2;
                    for (int i = 0; i < separatorsXs.Count; i += 2)
                    {
                        graphics.DrawLine(pen,
                                          new PointF(separatorsXs[i], sepY),
                                          new PointF(separatorsXs[i + 1], sepY));
                    }
                }
            }

            //Expander
            if (this.Expander && this.shadowOffSet == 0)
            {
                Bitmap bitmap = GetExpanderBitmap();
                this.expanderRectangle = GetExpanderCoordinates(graphics);
                graphics.DrawImage(bitmap, this.expanderRectangle.X, this.expanderRectangle.Y);
            }
        }