protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics G = e.Graphics;
            LinearGradientBrush linearGradientBrush1 = new LinearGradientBrush(//创建线性渐变画刷
            new Point(0, 0),new Point(20, 20),                  //渐变起始点和终止点
            Color.Yellow,Color.Blue);                           //渐变起始颜色和终止颜色
            G.FillRectangle(linearGradientBrush1, new Rectangle(0, 0, 150, 150));//绘制矩形
            LinearGradientBrush linearGradientBrush2 = new LinearGradientBrush(//创建线性渐变画刷
            new Rectangle(0, 0, 20, 20),                      //渐变所在矩形
            Color.Yellow, Color.Blue, 60f);                     //渐变起始颜色、终止颜色以及渐变方向
            linearGradientBrush2.WrapMode = WrapMode.TileFlipXY;
            G.FillRectangle(linearGradientBrush2, new Rectangle(150, 0, 150, 150));//绘制矩形

            GraphicsPath graphicsPath1 = new GraphicsPath();        //创建绘制路径
            graphicsPath1.AddArc(new Rectangle(0, 150, 100, 100), 90, 180);//向路径中添加半左圆弧
            graphicsPath1.AddArc(new Rectangle(150, 150, 100, 100), 270, 180);//向路径中添加半右圆弧
            graphicsPath1.CloseFigure();                            //闭合路径
            PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath1);//创建路径渐变画刷
            pathGradientBrush.CenterColor = Color.Yellow;           //指定画刷中心颜色
            pathGradientBrush.SurroundColors = new Color[] { Color.Blue };//指定画刷周边颜色
            pathGradientBrush.CenterPoint = new PointF(125, 200);   //指定画刷中心点坐标
            G.SmoothingMode = SmoothingMode.AntiAlias;              //消锯齿
            G.FillPath(pathGradientBrush, graphicsPath1);           //利用画刷填充路径
            G.DrawPath(new Pen(Color.Lime, 3f), graphicsPath1);     //绘制闭合路径曲线

            linearGradientBrush1.Dispose();
            linearGradientBrush2.Dispose();
            graphicsPath1.Dispose();
            pathGradientBrush.Dispose();
        }
		protected override void DrawSlider( PaintEventArgs e )
		{
			float		fSizeToDraw = m_SliderRectangle.Width * (Value - VisibleRangeMin) / (VisibleRangeMax - VisibleRangeMin);

			if ( m_ColorMin.A == 255 && m_ColorMax.A == 255 )
				e.Graphics.FillRectangle( m_BackgroundBrush, m_SliderRectangle.X + fSizeToDraw, m_SliderRectangle.Y, m_SliderRectangle.Width - fSizeToDraw, m_SliderRectangle.Height );
			else
			{	// Draw a nice checker box background
				System.Drawing.Drawing2D.HatchBrush	Checker = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, Color.Gray, Color.DarkGray );

				e.Graphics.FillRectangle( Checker, m_SliderRectangle );

				Checker.Dispose();
			}

			// Draw a gradient box
			if ( fSizeToDraw < 1.0f )
				return;	// Crashes if empty!

			RectangleF	Rect = new RectangleF( m_SliderRectangle.X, m_SliderRectangle.Y, fSizeToDraw, m_SliderRectangle.Height );

			System.Drawing.Drawing2D.GraphicsPath		Path = new System.Drawing.Drawing2D.GraphicsPath();
														Path.AddRectangle( Rect );

			System.Drawing.Drawing2D.PathGradientBrush	Gradient = new System.Drawing.Drawing2D.PathGradientBrush( Path );
														Gradient.SurroundColors = new Color[] { m_ColorMin, m_ColorMax, m_ColorMax, m_ColorMin };
 														Gradient.CenterPoint = new PointF( 0.5f * (Rect.Left + Rect.Right), .5f * (Rect.Bottom + Rect.Top) );
 														Gradient.CenterColor = Color.FromArgb( (m_ColorMin.A + m_ColorMax.A) / 2, (m_ColorMin.R + m_ColorMax.R) / 2, (m_ColorMin.G + m_ColorMax.G) / 2, (m_ColorMin.B + m_ColorMax.B) / 2 );

			e.Graphics.FillRectangle( Gradient, Rect );

 			Gradient.Dispose();
 			Path.Dispose();
		}
        /// <summary>
        /// Draws a radial gradient in the label
        /// </summary>
        /// <param name="e">paint arguments</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(this.ClientRectangle);

            PathGradientBrush brush = new PathGradientBrush(path);

            brush.CenterPoint = new PointF(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);
            brush.CenterColor = this.StartColor;
            brush.SurroundColors = new Color[] { this.EndColor };

            e.Graphics.FillPath(brush, path);

            brush.Dispose();
            path.Dispose();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics G = e.Graphics;
            G.SmoothingMode = SmoothingMode.AntiAlias;              //消除锯齿
            LinearGradientBrush brushOut = new LinearGradientBrush( //创建线性渐变画刷
            new Point(0, 0), new Point(20, 20), Color.Gray, Color.White);
            brushOut.WrapMode = WrapMode.TileFlipXY;
            G.FillPath(brushOut, pathOut);                          //填充外框路径
            PathGradientBrush brushIn = new PathGradientBrush(pathIn);//创建路径画刷
            brushIn.CenterColor = Color.White;
            brushIn.CenterPoint = new PointF(ClientRectangle.Width / 2, ClientRectangle.Height / 2);
            brushIn.SurroundColors = new Color[] { Color.Orange };
            G.FillPath(brushIn, pathIn);                            //填充内框路径
            G.DrawString(buttonText, Font, Brushes.Black, ClientRectangle, format);//绘制字符串
            brushOut.Dispose();
            brushIn.Dispose();
        }
Beispiel #5
0
        protected override void PaintStateBackground(ButtonItem button, Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
        {
            if (stateColors == null || stateColors.Background == null || stateColors.Background.IsEmpty)
                return;

            Rectangle shadowRect = r;
            ShadowPaintInfo spi = new ShadowPaintInfo();
            spi.Graphics = g;
            spi.Rectangle = shadowRect;
            ShadowPainter.Paint3(spi);

            r.Width -= 4;
            r.Height -= 4;
            r.Offset(1, 1);

            DisplayHelp.FillRectangle(g, r, stateColors.Background);
            if (stateColors.BottomBackgroundHighlight != null && !stateColors.BottomBackgroundHighlight.IsEmpty)
            {
                Rectangle ellipse = new Rectangle(r.X, r.Y + r.Height / 2 - 2, r.Width, r.Height + 4);
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse(ellipse);
                PathGradientBrush brush = new PathGradientBrush(path);
                brush.CenterColor = stateColors.BottomBackgroundHighlight.Start;
                brush.SurroundColors = new Color[] { stateColors.BottomBackgroundHighlight.End };
                brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, r.Bottom);
                Blend blend = new Blend();
                blend.Factors = new float[] { 0f, .5f, .6f };
                blend.Positions = new float[] { .0f, .4f, 1f };
                brush.Blend = blend;

                g.FillRectangle(brush, r);
                brush.Dispose();
                path.Dispose();
            }

            DisplayHelp.DrawGradientRectangle(g, r, stateColors.OuterBorder, 1);
            r.Inflate(-1, -1);
            DisplayHelp.DrawGradientRectangle(g, r, stateColors.InnerBorder, 1);
        }
        private void PaintView3(Graphics g)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddEllipse(ClientRectangle);

            PathGradientBrush pgb = new PathGradientBrush(gp);

            pgb.CenterPoint = new PointF(ClientRectangle.Width / 2,
                                         ClientRectangle.Height / 2);
            pgb.CenterPoint = new PointF(ClientRectangle.Width / 4,
                ClientRectangle.Height / 4);
            pgb.CenterColor = Color.White;
            pgb.SurroundColors = new Color[] { Color.Red };

            g.FillRectangle(pgb, this.ClientRectangle);
            pgb.Dispose();
            gp.Dispose();

            title = "Big Red Circle";
        }
        private void GlassSphere(Graphics g)
        {
            Color c = Color.Blue;
            int reduct = 200;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Base ellipse
            Rectangle r1 = new Rectangle(new Point(0, 0), new Size(this.Width-reduct, this.Height-reduct));
            Rectangle r2 = new Rectangle(r1.Location, new Size(r1.Size.Width - reduct - 2, r1.Size.Height - reduct - 2));

            GraphicsPath path = new GraphicsPath (FillMode.Winding);
            path.AddEllipse(r2);
            PathGradientBrush br1 = new PathGradientBrush(path);
            br1.CenterColor = c;
            br1.SurroundColors = new Color[] { Color.FromArgb(255, Color.Black) };
            //br1.CenterPoint = new PointF((float)(r1.Width / 1.5), r1.Top - Convert.ToInt16(r1.Height * 2));

            Blend bl1 = new Blend(5);
            bl1.Factors = new float[] { 0.5f, 1.0f, 1.0f, 1.0f, 1.0f };
            bl1.Positions = new float[] { 0.0f, 0.05f, 0.5f, 0.75f, 1.0f };
            br1.Blend = bl1;

            g.FillPath(br1, path);

            br1.Dispose();
            path.Dispose();

            // 1st hilite ellipse
            int r3w = Convert.ToInt16(r2.Width * 0.8);
            int r3h = Convert.ToInt16(r2.Height * 0.6);

            int r3posX = (r2.Width / 2) - (r3w / 2);
            int r3posY = r2.Top + 1;

            Rectangle r3 = new Rectangle(
                new Point(r3posX, r3posY),
                new Size(r3w, r3h));

            Color br3c1 = Color.White;
            Color br3c2 = Color.Transparent;

            LinearGradientBrush br2 = new LinearGradientBrush(r3, br3c1, br3c2, 90);
            br2.WrapMode = WrapMode.TileFlipX;
            g.FillEllipse(br2, r3);

            br2.Dispose();

            // 2nd hilite ellipse
            int r4w = Convert.ToInt16(r2.Width * 0.3);
            int r4h = Convert.ToInt16(r2.Height * 0.2);

            int r4posX = (r2.Width / 2) + (r4w / 2);
            int r4posY = r2.Top + Convert.ToInt16(r2.Height * 0.2);

            Rectangle r4 = new Rectangle(
                new Point(-(int)(r4w / 2), -(int)(r4h / 2)),
                new Size(r4w, r4h));

            LinearGradientBrush br3 = new LinearGradientBrush(r4, br3c1, br3c2, 90, true);
            g.TranslateTransform(r4posX, r4posY);
            g.RotateTransform(30);
            g.FillEllipse(br3, r4);

            br3.Dispose();
            title = "GlassSphere";
        }
        /// <summary>
        /// Draws a panel in selected state
        /// </summary>
        /// <param name="e"></param>
        public void DrawPanelSelected(RibbonPanelRenderEventArgs e)
        {

            #region Office_2007

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007)
            {
                Rectangle darkBorder = Rectangle.FromLTRB(
                      e.Panel.Bounds.Left,
                      e.Panel.Bounds.Top,
                      e.Panel.Bounds.Right,
                      e.Panel.Bounds.Bottom);

                Rectangle lightBorder = Rectangle.FromLTRB(
                     e.Panel.Bounds.Left + 1,
                     e.Panel.Bounds.Top + 1,
                     e.Panel.Bounds.Right - 1,
                     e.Panel.Bounds.Bottom - 1);

                Rectangle textArea =
                     Rectangle.FromLTRB(
                     e.Panel.Bounds.Left + 1,
                     e.Panel.ContentBounds.Bottom,
                     e.Panel.Bounds.Right - 1,
                     e.Panel.Bounds.Bottom - 1);

                GraphicsPath dark = RoundRectangle(darkBorder, 3);
                GraphicsPath light = RoundRectangle(lightBorder, 3);
                GraphicsPath txt = RoundRectangle(textArea, 3, Corners.SouthEast | Corners.SouthWest);

                using (Pen p = new Pen(ColorTable.PanelLightBorder))
                {
                    e.Graphics.DrawPath(p, light);
                }

                using (Pen p = new Pen(ColorTable.PanelDarkBorder))
                {
                    e.Graphics.DrawPath(p, dark);
                }

                using (SolidBrush b = new SolidBrush(ColorTable.PanelBackgroundSelected))
                {
                    e.Graphics.FillPath(b, light);
                }

                using (SolidBrush b = new SolidBrush(ColorTable.PanelTextBackgroundSelected))
                {
                    e.Graphics.FillPath(b, txt);
                }

                if (e.Panel.ButtonMoreVisible)
                {
                    if (e.Panel.ButtonMorePressed)
                    {
                        DrawButtonPressed(e.Graphics, e.Panel.ButtonMoreBounds, Corners.SouthEast, e.Ribbon);
                    }
                    else if (e.Panel.ButtonMoreSelected)
                    {
                        DrawButtonSelected(e.Graphics, e.Panel.ButtonMoreBounds, Corners.SouthEast, e.Ribbon);
                    }

                    DrawButtonMoreGlyph(e.Graphics, e.Panel.ButtonMoreBounds, e.Panel.ButtonMoreEnabled && e.Panel.Enabled);
                }

                txt.Dispose();
                dark.Dispose();
                light.Dispose();
            }

            #endregion

            #region Office_2010

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2010)
            {
                Rectangle innerLightBorder = Rectangle.FromLTRB(
                     e.Panel.Bounds.Left,
                     e.Panel.Bounds.Top,
                     e.Panel.Bounds.Right - 2,
                     e.Panel.Bounds.Bottom);

                Rectangle darkBorder = Rectangle.FromLTRB(
                      e.Panel.Bounds.Left,
                      e.Panel.Bounds.Top,
                      e.Panel.Bounds.Right - 1,
                      e.Panel.Bounds.Bottom);

                Rectangle outerLightBorder = Rectangle.FromLTRB(
                    e.Panel.Bounds.Left,
                    e.Panel.Bounds.Top,
                    e.Panel.Bounds.Right,
                    e.Panel.Bounds.Bottom);

                //Glow appears as a tall elipse, rather than circle
                Rectangle glowR = new Rectangle(
                     e.Panel.Bounds.Left + (int)(0.1 * e.Panel.Bounds.Width),
                     e.Panel.Bounds.Top,
                     e.Panel.Bounds.Width - (int)(0.2 * e.Panel.Bounds.Width),
                     (2 * e.Panel.Bounds.Height) - 1);

                //Highlight glow in panel
                using (GraphicsPath radialPath = new GraphicsPath())
                {
                    radialPath.AddArc(glowR, 180, 180);
                    radialPath.CloseFigure();

                    PathGradientBrush gr = new PathGradientBrush(radialPath);
                    gr.CenterPoint = new PointF(
                         Convert.ToSingle(innerLightBorder.Left + innerLightBorder.Width / 2),
                         Convert.ToSingle(innerLightBorder.Bottom));
                    gr.CenterColor = ColorTable.PanelBackgroundSelected;
                    gr.SurroundColors = new Color[] { Color.Transparent };
                    gr.SetSigmaBellShape(1.0f, 1.0f);

                    SmoothingMode sm = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillPath(gr, radialPath);
                    e.Graphics.SmoothingMode = sm;

                    gr.Dispose();
                }

                // Panel divider left highlight
                using (LinearGradientBrush blendBrush = new LinearGradientBrush(e.Panel.Bounds, Color.FromArgb(90, Color.White),
                   Color.FromArgb(220, Color.White), LinearGradientMode.Vertical))
                {
                    Blend blend = new Blend();
                    blend.Factors = new float[] { 0f, 1f, 1f };
                    blend.Positions = new float[] { 0f, 0.5f, 1f };
                    blendBrush.Blend = blend;
                    blendBrush.WrapMode = WrapMode.TileFlipX; //This is here to stop an annoying single pixel being drawn at the top of the line.

                    using (Pen p = new Pen(blendBrush))
                    {
                        SmoothingMode sm = e.Graphics.SmoothingMode;
                        e.Graphics.SmoothingMode = SmoothingMode.None;
                        e.Graphics.DrawLine(p, innerLightBorder.Right, innerLightBorder.Top, innerLightBorder.Right, innerLightBorder.Bottom);
                        e.Graphics.SmoothingMode = sm;
                    }
                }

                // Panel divider right highlight
                using (LinearGradientBrush blendBrush = new LinearGradientBrush(e.Panel.Bounds, Color.FromArgb(30, ColorTable.PanelLightBorder),
                    ColorTable.PanelLightBorder, LinearGradientMode.Vertical))
                {
                    using (Pen p = new Pen(blendBrush))
                    {
                        SmoothingMode sm = e.Graphics.SmoothingMode;
                        e.Graphics.SmoothingMode = SmoothingMode.None;
                        e.Graphics.DrawLine(p, outerLightBorder.Right, outerLightBorder.Top, outerLightBorder.Right, outerLightBorder.Bottom);
                        e.Graphics.SmoothingMode = sm;
                    }
                }

                // Panel divider shading
                using (LinearGradientBrush blendBrush = new LinearGradientBrush(e.Panel.Bounds, Color.FromArgb(30, ColorTable.PanelDarkBorder),
                    ColorTable.PanelDarkBorder, LinearGradientMode.Vertical))
                {
                    blendBrush.WrapMode = WrapMode.TileFlipX; //This is here to stop an annoying single pixel being drawn at the top of the line.

                    using (Pen p = new Pen(blendBrush))
                    {
                        SmoothingMode sm = e.Graphics.SmoothingMode;
                        e.Graphics.SmoothingMode = SmoothingMode.None;
                        e.Graphics.DrawLine(p, darkBorder.Right, darkBorder.Top, darkBorder.Right, darkBorder.Bottom);
                        e.Graphics.SmoothingMode = sm;
                    }
                }

                // Panel bottom border highlight
                /* For some reason this is not drawn except under certain circustances, like moving the mouse to a combobox, 
                 * or quickly outside the bounds of the Ribbon. Don't know exactly why, but probably clipping or the order of events being firing. 
                 * Have performed drawing tests with the ribbon, tab, panel drawn transparent and nothing appears to be drawing over the top. 
                 * Until resolved, will just leave the code in case some other change fixes it.*/
                using (Pen p = new Pen(Color.FromArgb(220, Color.White)))
                {
                    SmoothingMode sm = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.DrawLine(p, innerLightBorder.Left, innerLightBorder.Bottom, innerLightBorder.Right, innerLightBorder.Bottom);
                    //Enabling the line below shows that the line is drawn, but only the right hand half is shown. The left hand half is clipped/missing.
                    //e.Graphics.DrawLine(p, innerLightBorder.Left, innerLightBorder.Bottom, innerLightBorder.Right, innerLightBorder.Bottom - 1);
                    e.Graphics.SmoothingMode = sm;
                }

                if (e.Panel.ButtonMoreVisible)
                {
                    if (e.Panel.ButtonMorePressed)
                    {
                        DrawButtonPressed(e.Graphics, e.Panel.ButtonMoreBounds, Corners.SouthEast, e.Ribbon);
                    }
                    else if (e.Panel.ButtonMoreSelected)
                    {
                        DrawButtonSelected(e.Graphics, e.Panel.ButtonMoreBounds, Corners.SouthEast, e.Ribbon);
                    }

                    DrawButtonMoreGlyph(e.Graphics, e.Panel.ButtonMoreBounds, e.Panel.ButtonMoreEnabled && e.Panel.Enabled);
                }
            }

            #endregion

            #region Office_2013

            #endregion
        }
     private void GenerateCircle(Graphics g, float x, float y, float width, float height, int heading)
     {
         var outerRect = new RectangleF(x, y, width, height);

         // Fill the background of the whole control
         using (var bg = new SolidBrush(BackColor))
             g.FillRectangle(bg, outerRect);

         // Fill the background of the circle
         var circleRect = outerRect;
         circleRect.Inflate((_borderWidth/-2), (_borderWidth/-2));
         
         using (var white = new LinearGradientBrush(outerRect, _barBgLightColour, _barBgDarkColor, 0F))
                {
                  g.FillEllipse(white, circleRect);
                }
     
         var gp = new GraphicsPath();
         gp.AddEllipse(circleRect);

         var pgb = new PathGradientBrush(gp);

         pgb.CenterPoint = new PointF(circleRect.Width/2, circleRect.Height/2);
         pgb.CenterColor = _sweepDarkColour;
         pgb.SurroundColors = new[] {_sweepLightColour};

         heading = (heading + 270  -5)   %360;

         g.FillPie(pgb, circleRect.Left, circleRect.Top, circleRect.Width, circleRect.Height, heading, 10);

         pgb.Dispose();

         using (var borderPen = new Pen(_borderColor, _borderWidth))
         {
             g.DrawEllipse(borderPen, circleRect);
         }
     }
        /// <summary>
        /// Renders the clock's glass overlay.
        /// </summary>
        /// <param name="gfx">Graphics object used for rendering.</param>
        /// <param name="rect">Bounding rectangle.</param>
        protected virtual void DrawGlassOverlay(Graphics gfx, RectangleF rect)
        {
            GraphicsState gState;
            PathGradientBrush brush;
            GraphicsPath path, brushPath;
            PointF[] curvePoints;
            float radius;

            gState = gfx.Save();
            rect.Width *= 0.95f;
            rect.Height *= 0.95f;
            rect.X = -rect.Width / 2.0f;
            rect.Y = -rect.Height / 2.0f;
            radius = Math.Min(rect.Width, rect.Height) / 2.0f;

            brushPath = new GraphicsPath();
            brushPath.AddEllipse(rect);
            brush = new PathGradientBrush(brushPath);
            brush.CenterPoint = new PointF(0.0f, 0.0f);
            brush.CenterColor = Color.FromArgb(192, Color.White);
            brush.SurroundColors = new Color[] { Color.FromArgb(64, Color.White) };

            path = new GraphicsPath();
            path.AddArc(rect, 180, 180);
            curvePoints = new PointF[5];
            curvePoints[0].X = -radius;
            curvePoints[0].Y = 0.0f;

            curvePoints[1].X = -radius * 0.5f;
            curvePoints[1].Y = -radius * 0.175f;

            curvePoints[2].X = 0.0f;
            curvePoints[2].Y = -radius * 0.25f;

            curvePoints[3].X = radius * 0.5f;
            curvePoints[3].Y = -radius * 0.175f;

            curvePoints[4].X = radius;
            curvePoints[4].Y = 0.0f;

            path.AddCurve(curvePoints);
            path.CloseAllFigures();

            gfx.RotateTransform(_ClockStyleData.GlassAngle);
            gfx.FillPath(brush, path);

            gfx.Restore(gState);
            brush.Dispose();
            brushPath.Dispose();
            path.Dispose();

        }
        /// <summary>
        /// Updates Border panel image
        /// </summary>
        /// <param name="pg">Border Panel Graphics device</param>
        private void UpdateBorder(ref Graphics pg, ref Graphics pgc2)
        {
            //gnarly code goes here
            GraphicsPath gpath = new GraphicsPath();
            foreach (GridBase gb in BorderBases)
            {
                gpath.Reset();
                gpath.AddEllipse(gb.mx/20 - 6, gb.my/20 - 6, 12, 12);

                PathGradientBrush pgBrush = new PathGradientBrush(gpath);
                pgBrush.CenterPoint = new Point(gb.mx/20, gb.my/20);
                pgBrush.CenterColor = Color.FromArgb(254, 255, 255, 255);

                Color[] bcolor = { Color.FromArgb(1, 0, 0, 0) };
                pgBrush.SurroundColors = bcolor;
                if (gb.cityflag == 0)
                {
                    pg.FillEllipse(pgBrush, gb.mx / 20 - 6, gb.my / 20 - 6, 12, 12);
                }
                else
                {
                    pgc2.FillEllipse(pgBrush, gb.mx / 20 - 6, gb.my / 20 - 6, 12, 12);
                }
                pgBrush.Dispose();
            }
            gpath.Dispose();
            // update grid array with new values from image
        }
Beispiel #12
0
        protected virtual void PaintTabGroupBackground(Graphics g, Office2007RibbonTabGroupColorTable colorTable, Rectangle bounds, Rectangle groupBounds, bool glassEnabled)
        {
            if (colorTable == null)
                return;

            // Draw title rectangle part of the group
            Rectangle r = bounds;
            r.Height -= 2;

            // GDI+ bug
            Rectangle rFill = r;
            rFill.Width--;
            //rFill.Height--;

            // First draw background
            DisplayHelp.FillRectangle(g, rFill, colorTable.Background.Start, colorTable.Background.End, 90, new float[] { 0f, .10f, .9f }, new float[] { 0f, (glassEnabled?.4f:.70f), 1f });

            // Draw highlight
            if (!colorTable.BackgroundHighlight.IsEmpty && r.Width > 0 && r.Height > 0)
            {
                //Rectangle hr = new Rectangle(r.X, r.Bottom - 3, r.Width - 1, 3);
                //DisplayHelp.FillRectangle(g, hr, colorTable.BackgroundHighlight.Start, colorTable.BackgroundHighlight.End);
                Rectangle ellipse = new Rectangle(r.X - r.Width * 3, r.Y, r.Width * 7, (int)(r.Height * 4.5f));
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse(ellipse);
                PathGradientBrush brush = new PathGradientBrush(path);
                brush.CenterColor = colorTable.BackgroundHighlight.Start;
                brush.SurroundColors = new Color[] { colorTable.BackgroundHighlight.End };
                brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, r.Bottom);
                Blend blend = new Blend();
                blend.Factors = new float[] { 0f, .05f, 1f };
                blend.Positions = new float[] { .0f, .8f, 1f };
                brush.Blend = blend;
                path.Dispose();
                //rFill.Height++;
                g.FillRectangle(brush, rFill);
                brush.Dispose();
                path.Dispose();
            }
            // Underline highlight
            using (Pen pen = new Pen(Color.FromArgb(64, System.Windows.Forms.ControlPaint.Dark(colorTable.BackgroundHighlight.Start))))
                g.DrawLine(pen, r.X, r.Bottom, r.Right - 1, r.Bottom);

            r = bounds;
            SmoothingMode sm = g.SmoothingMode;
            g.SmoothingMode = SmoothingMode.Default;

            Rectangle rAll = groupBounds;

            if (!colorTable.Border.IsEmpty)
            {
                //using(SolidBrush brush=new SolidBrush(colorTable.Border.Start))
                //{
                //    // Draw border top
                //    g.FillRectangle(brush, bounds.X, bounds.Y, bounds.Width, 4);
                //}

                // Draw border ... Left first
                DisplayHelp.FillRectangle(g, new Rectangle(rAll.X, r.Y, 1, r.Height), colorTable.Border);

                // Then right
                DisplayHelp.FillRectangle(g, new Rectangle(rAll.Right - 1, r.Y, 1, r.Height), colorTable.Border);

                // Draw borders on the bottom...
                // Left first
                DisplayHelp.FillRectangle(g, new Rectangle(rAll.X, r.Bottom - 1, 1, rAll.Height - r.Height), colorTable.Border.End, Color.Transparent, 90);

                // Then right
                DisplayHelp.FillRectangle(g, new Rectangle(rAll.Right - 1, r.Bottom - 1, 1, rAll.Height - r.Height), colorTable.Border.End, Color.Transparent, 90);
            }
            g.SmoothingMode = sm;
        }
Beispiel #13
0
		private void DrawDropShadow(Graphics graphics, Rectangle rect, Color shadowColor, int shadowDepth, byte maxAlpha)
		{
			// Determine the shadow colors
			Color darkShadow = Color.FromArgb(maxAlpha, shadowColor);
			Color lightShadow = Color.FromArgb(0, shadowColor);

			// Create a brush that will create a softshadow circle
			GraphicsPath graphicsPath = new GraphicsPath();
			graphicsPath.AddEllipse(0, 0, 2 * shadowDepth, 2 * shadowDepth);

			PathGradientBrush brush = new PathGradientBrush(graphicsPath);
			brush.CenterColor = darkShadow;
			brush.SurroundColors = new Color[] { lightShadow };

			// Generate a softshadow pattern that can be used to paint the shadow
			Bitmap pattern = new Bitmap(2 * shadowDepth, 2 * shadowDepth);

			Graphics patternGraphics = Graphics.FromImage(pattern);
			patternGraphics.FillEllipse(brush, 0, 0, 2 * shadowDepth, 2 * shadowDepth);

			patternGraphics.Dispose();
			brush.Dispose();

			// Top right corner
			graphics.DrawImage(pattern, new Rectangle(rect.Right - shadowDepth, rect.Top + shadowDepth, shadowDepth, shadowDepth), shadowDepth, 0, shadowDepth, shadowDepth, GraphicsUnit.Pixel);

			// Right side
			graphics.DrawImage(pattern, new Rectangle(rect.Right - shadowDepth, rect.Top + 2 * shadowDepth, shadowDepth, rect.Height - 3 * shadowDepth), shadowDepth, shadowDepth, shadowDepth, 1, GraphicsUnit.Pixel);

			// Bottom right corner
			graphics.DrawImage(pattern, new Rectangle(rect.Right - shadowDepth, rect.Bottom - shadowDepth, shadowDepth, shadowDepth), shadowDepth, shadowDepth, shadowDepth, shadowDepth, GraphicsUnit.Pixel);

			// Bottom side
			graphics.DrawImage(pattern, new Rectangle(rect.Left + 2 * shadowDepth, rect.Bottom - shadowDepth, rect.Width - 3 * shadowDepth, shadowDepth), shadowDepth, shadowDepth, 1, shadowDepth, GraphicsUnit.Pixel);

			// Bottom left corner
			graphics.DrawImage(pattern, new Rectangle(rect.Left + shadowDepth, rect.Bottom - shadowDepth, shadowDepth, shadowDepth), 0, shadowDepth, shadowDepth, shadowDepth, GraphicsUnit.Pixel);

			pattern.Dispose();
		}
 /// <summary>
 /// Handles the drawing code for linear gradient paths.
 /// </summary>
 /// <param name="g"></param>
 /// <param name="gp"></param>
 public override void FillPath(Graphics g, GraphicsPath gp)
 {
     RectangleF bounds = Bounds;
     if (bounds.IsEmpty) bounds = gp.GetBounds();
     if (bounds.Width == 0 || bounds.Height == 0) return;
     //also don't draw gradient for very small polygons
     if (bounds.Width < 0.01 || bounds.Height < 0.01) return;
     if (_gradientType == GradientType.Linear)
     {
         LinearGradientBrush b = new LinearGradientBrush(bounds, _colors[0], _colors[_colors.Length - 1], (float)-_angle);
         ColorBlend cb = new ColorBlend();
         cb.Positions = _positions;
         cb.Colors = _colors;
         b.InterpolationColors = cb;
         g.FillPath(b, gp);
         b.Dispose();
     }
     else if (_gradientType == GradientType.Circular)
     {
         GraphicsPath round = new GraphicsPath();
         PointF center = new PointF(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
         float x = (float)(center.X - Math.Sqrt(2) * bounds.Width / 2);
         float y = (float)(center.Y - Math.Sqrt(2) * bounds.Height / 2);
         float w = (float)(bounds.Width * Math.Sqrt(2));
         float h = (float)(bounds.Height * Math.Sqrt(2));
         RectangleF circum = new RectangleF(x, y, w, h);
         round.AddEllipse(circum);
         PathGradientBrush pgb = new PathGradientBrush(round);
         ColorBlend cb = new ColorBlend();
         cb.Colors = _colors;
         cb.Positions = _positions;
         pgb.InterpolationColors = cb;
         g.FillPath(pgb, gp);
         pgb.Dispose();
     }
     else if (_gradientType == GradientType.Rectangular)
     {
         GraphicsPath rect = new GraphicsPath();
         PointF[] points = new PointF[5];
         PointF center = new PointF(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
         double a = bounds.Width / 2;
         double b = bounds.Height / 2;
         double angle = _angle;
         if (angle < 0) angle = 360 + angle;
         angle = angle % 90;
         angle = 2 * (Math.PI * angle / 180);
         double x = a * Math.Cos(angle);
         double y = -b - a * Math.Sin(angle);
         points[0] = new PointF((float)x + center.X, (float)y + center.Y);
         x = a + b * Math.Sin(angle);
         y = b * Math.Cos(angle);
         points[1] = new PointF((float)x + center.X, (float)y + center.Y);
         x = -a * Math.Cos(angle);
         y = b + a * Math.Sin(angle);
         points[2] = new PointF((float)x + center.X, (float)y + center.Y);
         x = -a - b * Math.Sin(angle);
         y = -b * Math.Cos(angle);
         points[3] = new PointF((float)x + center.X, (float)y + center.Y);
         points[4] = points[0];
         rect.AddPolygon(points);
         PathGradientBrush pgb = new PathGradientBrush(rect);
         ColorBlend cb = new ColorBlend();
         cb.Colors = _colors;
         cb.Positions = _positions;
         pgb.InterpolationColors = cb;
         g.FillPath(pgb, gp);
         pgb.Dispose();
     }
 }
Beispiel #15
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            Graphics g = pevent.Graphics;
            g.FillRectangle(SystemBrushes.Control, 0, 0, Width, Height);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            // Create painting objects
            Brush b = new SolidBrush(this.ForeColor);

            // Create Rectangle To Limit brush area.
            Rectangle rect = new Rectangle(0, 0, Width, Height);

            LinearGradientBrush linearBrush = null;
            if(Enabled)
              linearBrush = new LinearGradientBrush(rect,
              gradientStart,
              gradientEnd,
              _rotation);
            else
                linearBrush = new LinearGradientBrush(rect,
                Color.SlateGray,
                Color.DarkGray,
                _rotation);
            LinearGradientBrush highlightBrush =
              new LinearGradientBrush(rect,
              highGradientStart,
              highGradientEnd,
              _rotation);

            path = new GraphicsPath();
            innerPath = new GraphicsPath();
            float textX = Width / 2;
            float textY = Height / 2;
            Region cliphover = Region;
            switch (Rotation)
            {
                case 0:
                    {
                        int h = Height-1;
                        int w = Width-1;
                        int wa = w - arrowHeadWidth;
                        int h1 = (int)(h * (1 - arrowBaseHeight) / 2.0f);
                        PointF[] la =
             {
                 new PointF(1,h1),
                 new PointF(wa,h1),
                 new PointF(wa,1),
                 new PointF(w,h/2),
                 new PointF(wa,h),
                 new PointF(wa,h-h1),
                 new PointF(1,h-h1),
                 new PointF(1,h1)
             };
                        path.AddLines(la);
                        PointF[] la2 =
             {
                 new PointF(0,h1-1),
                 new PointF(wa-1,h1-1),
                 new PointF(wa-1,0),
                 new PointF(w+1,h/2),
                 new PointF(wa-1,h+1),
                 new PointF(wa-1,h-h1+1),
                 new PointF(0,h-h1+1),
                 new PointF(0,h1-1)
             };
                        innerPath.AddLines(la2);
                        cliphover = new Region(new Rectangle(0, 0, hoverWidth, Height));
                    }
                    break;
                case 90:
                    {
                        int h = Height - 1;
                        int w = Width - 1;
                        int ha = h-arrowHeadWidth+1;
                        int w1 = (int)(w * (1 - arrowBaseHeight) / 2.0f);
                        PointF[] la =
             {
                 new PointF(w1,1),
                 new PointF(w1,ha),
                 new PointF(1,ha),
                 new PointF(w/2,h),
                 new PointF(w,ha),
                 new PointF(w-w1,ha),
                 new PointF(w-w1,1),
                 new PointF(w1,1)
             };
                        path.AddLines(la);
                        PointF[] la2 =
             {
                 new PointF(w1-1,0),
                 new PointF(w1-1,ha-1),
                 new PointF(0,ha-1),
                 new PointF(w/2,h+1),
                 new PointF(w+1,ha-1),
                 new PointF(w-w1+1,ha-1),
                 new PointF(w-w1+1,0),
                 new PointF(w1-1,0)
             };
                        innerPath.AddLines(la2);
                        cliphover = new Region(new Rectangle(0, 0, Width, hoverWidth));

                    }
                    break;
                case 180:
                    {
                        int h = Height - 1;
                        int w = Width - 1;
                        int wa = arrowHeadWidth+1;
                        int h1 = (int)(h * (1 - arrowBaseHeight) / 2.0f);
                        PointF[] la =
             {
                 new PointF(w,h1),
                 new PointF(wa,h1),
                 new PointF(wa,1),
                 new PointF(1,h/2),
                 new PointF(wa,h),
                 new PointF(wa,h-h1),
                 new PointF(w,h-h1),
                 new PointF(w,h1)
             };
                        path.AddLines(la);
                        PointF[] la2 =
             {
                 new PointF(w+1,h1-1),
                 new PointF(wa-1,h1-1),
                 new PointF(wa-1,0),
                 new PointF(0,h/2),
                 new PointF(wa-1,h+1),
                 new PointF(wa-1,h-h1+1),
                 new PointF(w+1,h-h1+1),
                 new PointF(w+1,h1-1)
             };
                        innerPath.AddLines(la2);

                    }
                    cliphover = new Region(new Rectangle(Width-hoverWidth, 0, hoverWidth, Height));
                    break;
                case 270:
                    {
                        int h = Height - 1;
                        int w = Width - 1;
                        int ha = arrowHeadWidth + 1;
                        int w1 = (int)(w * (1 - arrowBaseHeight) / 2.0f);
                        PointF[] la =
             {
                 new PointF(w1,h),
                 new PointF(w1,ha),
                 new PointF(1,ha),
                 new PointF(w/2,1),
                 new PointF(w,ha),
                 new PointF(w-w1,ha),
                 new PointF(w-w1,h),
                 new PointF(w1,h)
             };
                        path.AddLines(la);
                        PointF[] la2 =
             {
                 new PointF(w1-1,h+1),
                 new PointF(w1-1,ha+1),
                 new PointF(0,ha-1),
                 new PointF(w/2,0),
                 new PointF(w+1,ha+1),
                 new PointF(w-w1+1,ha+1),
                 new PointF(w-w1+1,h+1),
                 new PointF(w1-1,h+1)
             };
                        innerPath.AddLines(la2);

                        cliphover = new Region(new Rectangle(0, Height-hoverWidth, Width, hoverWidth));
                    }
                    break;
            }
            //this.Region = new Region(innerPath); // Set shape for hit detection
            Brush fontBrush = Brushes.Black;
            PathGradientBrush pgbrush = new PathGradientBrush(innerPath);
            pgbrush.CenterPoint = new Point(75, 75);
            pgbrush.CenterColor = Color.White;
            pgbrush.SurroundColors = new Color[] { this.ForeColor };
            Pen p = new Pen(borderColor, 1);
            g.FillPath(linearBrush, path);
            Region clip = g.Clip;
            g.Clip = cliphover;
            g.FillPath(highlightBrush, path);
            // Draw seperations
            string[] va = possibleValues.Split(';');
            g.Clip = new Region(path);
            switch (_rotation)
            {
                case 0: {
                    for (int i = 0; i < va.Length-1; i++)
                    {
                        int pos = (i + 1) * Width / va.Length;
                        g.DrawLine(Pens.DarkGray,pos,0,pos,Height);
                    }
                }
                    break;
                case 180:
                    {
                        for (int i = 0; i < va.Length - 1; i++)
                        {
                            int pos = Width-(i + 1) * Width / va.Length;
                            g.DrawLine(Pens.DarkGray, pos, 0, pos, Height);
                        }
                    }
                    break;
                case 90:
                    {
                        for (int i = 0; i < va.Length - 1; i++)
                        {
                            int pos = (i + 1) * Height / va.Length;
                            g.DrawLine(Pens.DarkGray,0, pos, Width, pos);
                        }
                    }
                    break;
                case 270:
                    {
                        for (int i = 0; i < va.Length - 1; i++)
                        {
                            int pos = Height - (i + 1) * Height / va.Length;
                            g.DrawLine(Pens.DarkGray,0, pos, Width, pos);
                        }
                    }
                    break;
            }
            g.Clip = clip;
            g.DrawPath(p, path);
            SizeF fsize = g.MeasureString(title, drawFont);
            textX -= fsize.Width / 2;
            textY -= fsize.Height / 2;
            g.DrawString(title, drawFont, fontBrush, textX, textY);
            // Dispose of painting objects
            b.Dispose();
            p.Dispose();
            pgbrush.Dispose();
            linearBrush.Dispose();
            highlightBrush.Dispose();
        }
Beispiel #16
0
        private void Draw_Click(object sender, EventArgs e)
        {
            this.Text = "Drawing in progress...";
            Point[] points = new Point[3];
            GraphicsPath brushPath = new GraphicsPath();
            pictureBox3.Image = bmpLines;
            for (int i = 0; i < triangles.Count; i++)
            {
                points[0] = new Point(triangles[i].v1.x, triangles[i].v1.y);
                points[1] = new Point(triangles[i].v2.x, triangles[i].v2.y);
                points[2] = new Point(triangles[i].v3.x, triangles[i].v3.y);
                //brushPath.AddPolygon(points);
                brushPath.StartFigure();
                brushPath.AddLine(points[0], points[1]);
                brushPath.AddLine(points[0], points[2]);
                brushPath.AddLine(points[1], points[2]);
                brushPath.CloseFigure();

                using (var brush = new PathGradientBrush(brushPath))
                {
                    gradient(points, brush, triangles[i], brushPath);
                    brush.Dispose();
                    pictureBox3.Refresh();
                }
            }
            this.Text = "ImageChanger";
        }
    FillCircle3D
    (
        Graphics oGraphics,
        Color oColor,
        Single fXCenter,
        Single fYCenter,
        Single fRadius
    )
    {
        Debug.Assert(oGraphics != null);
        Debug.Assert(fRadius > 0);

        // The following code is based on the BouncingGradientBrushBall.cs
        // example in "Programming Windows with C#," by Petzold.

        GraphicsPath oGraphicsPath = new GraphicsPath();

        // Add the circle to the path.

        RectangleF oRectangleF =
            SquareFromCenterAndHalfWidth(fXCenter, fYCenter, fRadius);

        oGraphicsPath.AddEllipse(oRectangleF);

        PathGradientBrush oPathGradientBrush =
            new PathGradientBrush(oGraphicsPath);

        // Specify white for the point 1/3 to the left and top of the circle's
        // bounding rectangle.

        oPathGradientBrush.CenterPoint = new PointF(
            oRectangleF.Left + oRectangleF.Width / 3F,
            oRectangleF.Top + oRectangleF.Height / 3F);

        oPathGradientBrush.CenterColor = Color.White;

        // Use the specified color for the single surround color.

        oPathGradientBrush.SurroundColors = new Color [] {oColor};

        // Fill the circle with the gradient brush.

        oGraphics.FillRectangle(oPathGradientBrush, oRectangleF);

        oPathGradientBrush.Dispose();
        oGraphicsPath.Dispose();
    }
Beispiel #18
0
        public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
        {
            float topSplit = .35f;
            float bottomSplit = .65f;
            if (!shape.CanDrawShape(r)) return;

            if (stateColors != null)
            {
                Rectangle fillRectangle = r;
                
                Rectangle backRect = new Rectangle(fillRectangle.X, fillRectangle.Y, fillRectangle.Width, (int)(fillRectangle.Height * topSplit));
                if (!stateColors.OuterBorder.IsEmpty && paintBorder)
                    fillRectangle.Width--;
                GraphicsPath backPath = shape.GetShape(fillRectangle);
                if (stateColors.Background != null)
                {
                    if (backPath != null)
                    {
                        if (stateColors.Background.End.IsEmpty)
                        {
                            using (SolidBrush brush = new SolidBrush(stateColors.Background.Start))
                                g.FillPath(brush, backPath);
                        }
                        else
                        {
                            using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.Background.Start, stateColors.Background.End, stateColors.Background.GradientAngle))
                            {
                                g.FillPath(lb, backPath);
                            }
                        }
                        backPath.Dispose();
                    }
                }
                else
                {
                    if (backPath != null && stateColors.TopBackground!= null && stateColors.BottomBackground!=null)
                    {
                        if (stateColors.TopBackground.End.IsEmpty && stateColors.BottomBackground.End.IsEmpty)
                        {
                            if (stateColors.TopBackground.Start == stateColors.BottomBackground.Start)
                                using (SolidBrush lb = new SolidBrush(stateColors.TopBackground.Start))
                                    g.FillPath(lb, backPath);
                            else
                            {
                                using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.TopBackground.Start, stateColors.BottomBackground.Start, stateColors.TopBackground.GradientAngle))
                                {
                                    g.FillPath(lb, backPath);
                                }
                            }
                        }
                        else
                        {
                            using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.TopBackground.Start, stateColors.BottomBackground.End, stateColors.TopBackground.GradientAngle))
                            {
                                ColorBlend cb = new ColorBlend(4);
                                cb.Colors = new Color[] { stateColors.TopBackground.Start, stateColors.TopBackground.End, stateColors.BottomBackground.Start, stateColors.BottomBackground.End };
                                cb.Positions = new float[] { 0, topSplit, topSplit, 1f };
                                lb.InterpolationColors = cb;
                                g.FillPath(lb, backPath);
                            }
                        }
                        backPath.Dispose();
                    }

                    if (stateColors.TopBackgroundHighlight!=null && !stateColors.TopBackgroundHighlight.IsEmpty)
                    {
                        Rectangle ellipse = new Rectangle(fillRectangle.X, fillRectangle.Y, fillRectangle.Width, fillRectangle.Height);
                        GraphicsPath path = new GraphicsPath();
                        path.AddEllipse(ellipse);
                        PathGradientBrush brush = new PathGradientBrush(path);
                        brush.CenterColor = stateColors.TopBackgroundHighlight.Start;
                        brush.SurroundColors = new Color[] { stateColors.TopBackgroundHighlight.End };
                        brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom);
                        Blend blend = new Blend();
                        blend.Factors = new float[] { 0f, .5f, 1f };
                        blend.Positions = new float[] { .0f, .4f, 1f };
                        brush.Blend = blend;

                        g.FillRectangle(brush, backRect);
                        brush.Dispose();
                        path.Dispose();
                    }

                    // Draw Bottom part
                    int bottomHeight = (int)(fillRectangle.Height * bottomSplit);
                    backRect = new Rectangle(fillRectangle.X, fillRectangle.Y + backRect.Height, fillRectangle.Width, fillRectangle.Height - backRect.Height);

                    if (stateColors.BottomBackgroundHighlight!=null && !stateColors.BottomBackgroundHighlight.IsEmpty)
                    {
                        Rectangle ellipse = new Rectangle(fillRectangle.X, fillRectangle.Y + bottomHeight - 2, fillRectangle.Width, fillRectangle.Height + 4);
                        GraphicsPath path = new GraphicsPath();
                        path.AddEllipse(ellipse);
                        PathGradientBrush brush = new PathGradientBrush(path);
                        brush.CenterColor = stateColors.BottomBackgroundHighlight.Start;
                        brush.SurroundColors = new Color[] { stateColors.BottomBackgroundHighlight.End };
                        brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom);
                        Blend blend = new Blend();
                        blend.Factors = new float[] { 0f, .5f, .6f };
                        blend.Positions = new float[] { .0f, .4f, 1f };
                        brush.Blend = blend;

                        g.FillRectangle(brush, backRect);
                        brush.Dispose();
                        path.Dispose();
                    }
                }

                if (paintBorder)
                {
                    SmoothingMode sm = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    // Draw Border
                    if (!stateColors.OuterBorder.IsEmpty && stateColors.OuterBorderWidth>0)
                    {
                        Rectangle br = r;
                        br.Width--;
                        br.Height--;

                        if (shape is EllipticalShapeDescriptor && stateColors.OuterBorder.End.IsEmpty)
                        {
                            br.Width -= (stateColors.OuterBorderWidth / 2);
                            br.Height -= (stateColors.OuterBorderWidth / 2);
                            using (Pen pen = new Pen(stateColors.OuterBorder.Start, stateColors.OuterBorderWidth))
                                g.DrawEllipse(pen, br);
                        }
                        else
                        {
                            GraphicsPath path = shape.GetShape(br);
                            if (path != null)
                            {
                                DisplayHelp.DrawGradientPath(g, path, r, stateColors.OuterBorder, stateColors.OuterBorderWidth);
                                path.Dispose();
                            }
                        }
                        //if (cornerSize > 1)
                        //    DisplayHelp.DrawRoundGradientRectangle(g, r, stateColors.OuterBorder, 1, cornerSize);
                        //else
                        //    DisplayHelp.DrawGradientRectangle(g, r, stateColors.OuterBorder, 1);

                        if (isDefault)
                        {
                            Color clr = Color.FromArgb(128, stateColors.OuterBorder.Start);
                            r.Inflate(-1, -1);
                            DisplayHelp.DrawRectangle(g, clr, r);
                            r.Inflate(-1, -1);
                            DisplayHelp.DrawRectangle(g, clr, r);
                        }
                    }
                    if (!isDefault && !stateColors.InnerBorder.IsEmpty)
                    {
                        Rectangle innerRect = r;
                        innerRect.Inflate(-1, -1);
                        innerRect.Width--;
                        innerRect.Height--;
                        using (GraphicsPath path = shape.GetInnerShape(innerRect, 1))
                            DisplayHelp.DrawGradientPath(g, path, innerRect, stateColors.InnerBorder, 1);
                        //cornerSize--;
                        //if (cornerSize > 1)
                        //    DisplayHelp.DrawRoundGradientRectangle(g, innerRect, stateColors.InnerBorder, 1, cornerSize);
                        //else
                        //    DisplayHelp.DrawGradientRectangle(g, innerRect, stateColors.InnerBorder, 1);
                    }

                    g.SmoothingMode = sm;
                }
            }
        }
    FillSquare3D
    (
        Graphics oGraphics,
        Color oColor,
        Single fXCenter,
        Single fYCenter,
        Single fHalfWidth
    )
    {
        Debug.Assert(oGraphics != null);
        Debug.Assert(fHalfWidth >= 0);

        // The following code is based on the BouncingGradientBrushBall.cs
        // example in "Programming Windows with C#," by Petzold.

        GraphicsPath oGraphicsPath = new GraphicsPath();

        // Add the square to the path.

        RectangleF oRectangleF = 
            SquareFromCenterAndHalfWidth(fXCenter, fYCenter, fHalfWidth);

        oGraphicsPath.AddRectangle(oRectangleF);

        PathGradientBrush oPathGradientBrush =
            new PathGradientBrush(oGraphicsPath);

        // Specify white for the center point.

        oPathGradientBrush.CenterPoint = new PointF(fXCenter, fYCenter);
        oPathGradientBrush.CenterColor = Color.White;

        // Use the specified color for the single surround color.

        oPathGradientBrush.SurroundColors = new Color [] {oColor};

        // Fill the square with the gradient brush.

        oGraphics.FillRectangle(oPathGradientBrush, oRectangleF);

        oPathGradientBrush.Dispose();
        oGraphicsPath.Dispose();
    }
        /// <summary>
        /// Draws a selected tab
        /// </summary>
        /// <param name="e"></param>
        public void DrawTabSelected(RibbonTabRenderEventArgs e)
        {
            Rectangle outerR = Rectangle.FromLTRB(
                 e.Tab.TabBounds.Left,
                 e.Tab.TabBounds.Top,
                 e.Tab.TabBounds.Right - 1,
                 e.Tab.TabBounds.Bottom);
            Rectangle innerR = Rectangle.FromLTRB(
                 outerR.Left + 1,
                 outerR.Top + 1,
                 outerR.Right - 1,
                 outerR.Bottom);

            Rectangle glossyR = Rectangle.FromLTRB(
                 innerR.Left + 1,
                 innerR.Top + 1,
                 innerR.Right - 1,
                 innerR.Top + e.Tab.TabBounds.Height / 2);

            GraphicsPath outer = RoundRectangle(outerR, 3, Corners.NorthEast | Corners.NorthWest);
            GraphicsPath inner = RoundRectangle(innerR, 3, Corners.NorthEast | Corners.NorthWest);
            GraphicsPath glossy = RoundRectangle(glossyR, 3, Corners.NorthEast | Corners.NorthWest);

            using (Pen p = new Pen(ColorTable.TabBorder))
            {
                e.Graphics.DrawPath(p, outer);
            }

            using (Pen p = new Pen(Color.FromArgb(200, Color.White)))
            {
                e.Graphics.DrawPath(p, inner);
            }

            using (GraphicsPath radialPath = new GraphicsPath())
            {
                radialPath.AddRectangle(innerR);
                //radialPath.AddEllipse(innerR);
                radialPath.CloseFigure();

                PathGradientBrush gr = new PathGradientBrush(radialPath);
                gr.CenterPoint = new PointF(
                     Convert.ToSingle(innerR.Left + innerR.Width / 2),
                     Convert.ToSingle(innerR.Top - 5));
                gr.CenterColor = Color.Transparent;
                gr.SurroundColors = new Color[] { ColorTable.TabSelectedGlow };

                Blend blend = new Blend(3);
                blend.Factors = new float[] { 0.0f, 0.9f, 0.0f };
                blend.Positions = new float[] { 0.0f, 0.8f, 1.0f };

                gr.Blend = blend;

                e.Graphics.FillPath(gr, radialPath);

                gr.Dispose();
            }
            using (SolidBrush b = new SolidBrush(Color.FromArgb(100, Color.White)))
            {
                e.Graphics.FillPath(b, glossy);
            }

            outer.Dispose();
            inner.Dispose();
            glossy.Dispose();
        }
Beispiel #21
0
        /// <summary>
        /// Draw a drop shadow
        /// </summary>
        /// <param name="g">The graphics object to use</param>
        /// <param name="offx">Offset from the current position to draw the shadow</param>
        /// <param name="offy"></param>
        public void DrawDropShadow(Graphics g, float offx, float offy)
        {
            PathGradientBrush b = null;
            GraphicsPath path = GetPath();

            try
            {
                Matrix m = new Matrix();
                m.Translate(offx, offy);
                path.Transform(m);
                b = new PathGradientBrush(path);

                b.WrapMode = WrapMode.Clamp;
                ColorBlend colors = new ColorBlend(3);

                colors.Colors = new Color[] {Color.Transparent, Color.FromArgb(180, Color.DimGray),  Color.FromArgb(180, Color.DimGray)};
                colors.Positions = new float[] { 0.0f, 0.1f, 1.0f };
                b.InterpolationColors = colors;
                g.FillPath(b, path);
            }
            finally
            {
                if (path != null)
                {
                    path.Dispose();
                }

                if (b != null)
                {
                    b.Dispose();
                }
            }
        }
        /// <summary>
        /// Draws a selected tab
        /// </summary>
        /// <param name="e"></param>
        //Michael Spradlin - 05/03/2013 Office 2013 Style Changes
        public void DrawTabMinimized(RibbonTabRenderEventArgs e)
        {
            if (e.Tab.Invisible)
                return;

            if (e.Tab.Selected)
            {
                #region Office_2007

                if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007)
                {
                    Rectangle outerR = Rectangle.FromLTRB(
                          e.Tab.TabBounds.Left,
                          e.Tab.TabBounds.Top,
                          e.Tab.TabBounds.Right - 1,
                          e.Tab.TabBounds.Bottom);
                    Rectangle innerR = Rectangle.FromLTRB(
                         outerR.Left + 1,
                         outerR.Top + 1,
                         outerR.Right - 1,
                         outerR.Bottom);

                    Rectangle glossyR = Rectangle.FromLTRB(
                         innerR.Left + 1,
                         innerR.Top + 1,
                         innerR.Right - 1,
                         innerR.Top + e.Tab.TabBounds.Height / 2);

                    GraphicsPath outer = RoundRectangle(outerR, 3, Corners.NorthEast | Corners.NorthWest);
                    GraphicsPath inner = RoundRectangle(innerR, 3, Corners.NorthEast | Corners.NorthWest);
                    GraphicsPath glossy = RoundRectangle(glossyR, 3, Corners.NorthEast | Corners.NorthWest);

                    using (Pen p = new Pen(ColorTable.TabBorder))
                    {
                        e.Graphics.DrawPath(p, outer);
                    }

                    using (Pen p = new Pen(Color.FromArgb(200, Color.White)))
                    {
                        e.Graphics.DrawPath(p, inner);
                    }

                    using (GraphicsPath radialPath = new GraphicsPath())
                    {
                        radialPath.AddRectangle(innerR);
                        //radialPath.AddEllipse(innerR);
                        radialPath.CloseFigure();

                        PathGradientBrush gr = new PathGradientBrush(radialPath);
                        gr.CenterPoint = new PointF(
                             Convert.ToSingle(innerR.Left + innerR.Width / 2),
                             Convert.ToSingle(innerR.Top - 5));
                        gr.CenterColor = Color.Transparent;
                        gr.SurroundColors = new Color[] { ColorTable.TabSelectedGlow };

                        Blend blend = new Blend(3);
                        blend.Factors = new float[] { 0.0f, 0.9f, 0.0f };
                        blend.Positions = new float[] { 0.0f, 0.8f, 1.0f };

                        gr.Blend = blend;

                        e.Graphics.FillPath(gr, radialPath);

                        gr.Dispose();
                    }
                    using (SolidBrush b = new SolidBrush(Color.FromArgb(100, Color.White)))
                    {
                        e.Graphics.FillPath(b, glossy);
                    }

                    outer.Dispose();
                    inner.Dispose();
                    glossy.Dispose();
                }

                #endregion

                #region Office_2010

                if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2010)
                {
                    //background
                    Rectangle outerR = Rectangle.FromLTRB(e.Tab.TabBounds.Left, e.Tab.TabBounds.Top, e.Tab.TabBounds.Right - 1, e.Tab.TabBounds.Bottom);
                    Rectangle innerR = Rectangle.FromLTRB(outerR.Left + 1, outerR.Top + 1, outerR.Right - 1, outerR.Bottom);
                    Rectangle glossyR = Rectangle.FromLTRB(innerR.Left + 1, innerR.Top + 1, innerR.Right - 1, innerR.Top + e.Tab.TabBounds.Height);

                    GraphicsPath outer = RoundRectangle(outerR, 3, Corners.NorthEast | Corners.NorthWest);
                    GraphicsPath inner = RoundRectangle(innerR, 3, Corners.NorthEast | Corners.NorthWest);
                    GraphicsPath glossy = RoundRectangle(glossyR, 3, Corners.NorthEast | Corners.NorthWest);

                    //Tab border
                    using (GraphicsPath path = CreateTabPath_2010(e.Tab))
                    {
                        using (Pen p = new Pen(ColorTable.TabSelectedBorder))
                        {
                            SmoothingMode sm = e.Graphics.SmoothingMode;
                            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                            e.Graphics.DrawPath(p, path);
                            e.Graphics.SmoothingMode = sm;
                        }
                    }

                    //Interior shading and highlight
                    using (GraphicsPath radialPath = new GraphicsPath())
                    {
                        radialPath.AddRectangle(innerR);
                        radialPath.CloseFigure();

                        LinearGradientBrush b = new LinearGradientBrush(innerR, Color.FromArgb(50, Color.Gray), Color.FromArgb(80, Color.White), 90);

                        Blend blend = new Blend(3);
                        blend.Factors = new float[] { 0.0f, 0.6f, 1.0f };
                        blend.Positions = new float[] { 0.0f, 0.2f, 1.0f };

                        b.Blend = blend;

                        e.Graphics.FillPath(b, radialPath);

                        b.Dispose();
                    }

                    //Interior white line
                    using (Pen p = new Pen(Color.FromArgb(200, Color.White)))
                    {
                        e.Graphics.DrawPath(p, inner);
                    }
                }

                #endregion

                #region Office_2013

                if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2013)
                {
                    //background
                    Rectangle outerR = Rectangle.FromLTRB(e.Tab.TabBounds.Left, e.Tab.TabBounds.Top, e.Tab.TabBounds.Right - 1, e.Tab.TabBounds.Bottom);
                    Rectangle innerR = Rectangle.FromLTRB(outerR.Left + 1, outerR.Top + 1, outerR.Right - 1, outerR.Bottom);
                    Rectangle glossyR = Rectangle.FromLTRB(innerR.Left + 1, innerR.Top + 1, innerR.Right - 1, innerR.Top + e.Tab.TabBounds.Height);

                    GraphicsPath outer = FlatRectangle(outerR);
                    GraphicsPath inner = FlatRectangle(innerR);
                    GraphicsPath glossy = FlatRectangle(glossyR);

                    using (SolidBrush b = new SolidBrush(ColorTable.ButtonSelected_2013))
                    {
                        e.Graphics.FillPath(b, outer);
                    }

                    //Tab border
                    using (GraphicsPath path = CreateTabPath_2013(e.Tab))
                    {
                        using (Pen p = new Pen(ColorTable.ButtonSelected_2013))
                        {
                            SmoothingMode sm = e.Graphics.SmoothingMode;
                            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                            e.Graphics.DrawPath(p, path);
                            e.Graphics.SmoothingMode = sm;
                        }
                    }
                }

                #endregion

            }
            else
            {
                RectangleF lastClip = e.Graphics.ClipBounds;

                Rectangle clip = Rectangle.FromLTRB(
                          e.Tab.TabBounds.Left,
                          e.Tab.TabBounds.Top,
                          e.Tab.TabBounds.Right,
                          e.Tab.TabBounds.Bottom);

                Rectangle r = Rectangle.FromLTRB(
                     e.Tab.TabBounds.Left - 1,
                     e.Tab.TabBounds.Top - 1,
                     e.Tab.TabBounds.Right,
                     e.Tab.TabBounds.Bottom);

                e.Graphics.SetClip(clip);

                if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007)
                {
                    using (Brush b = new SolidBrush(ColorTable.RibbonBackground))
                    {
                        e.Graphics.FillRectangle(b, r);
                    }
                }
                if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2010)
                {
                    if (e.Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaGlass)
                    {
                        WinApi.FillForGlass(e.Graphics, r);
                    }
                    else
                    {
                        using (Brush b = new SolidBrush(ColorTable.RibbonBackground))
                        {
                            e.Graphics.FillRectangle(b, r);
                        }
                    }
                }
                if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2013)
                {
                    if (e.Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaGlass)
                    {
                        WinApi.FillForGlass(e.Graphics, r);
                    }
                    else
                    {
                        using (Brush b = new SolidBrush(ColorTable.RibbonBackground_2013))
                        {
                            e.Graphics.FillRectangle(b, r);
                        }
                    }
                }
                e.Graphics.SetClip(lastClip);
            }
        }
 private void DrawFloatValue(ref Graphics g)
 {
     SizeF sz = g.MeasureString(_Value.ToString(), _FloatValueFont, new PointF(0, 0), StringFormat.GenericDefault);
     Rectangle rect = default(Rectangle);
     PathGradientBrush pbr = null;
     GraphicsPath gp = new GraphicsPath();
     if (_Orientation == System.Windows.Forms.Orientation.Horizontal) {
         rect = new Rectangle(Convert.ToInt32(sngSliderPos - (sz.Width / 2)), Convert.ToInt32((rectSlider.Height / 2) + rectSlider.Y - (_SliderSize.Height / 2) - 1 - sz.Height), Convert.ToInt32(sz.Width) + 1, Convert.ToInt32(sz.Height));
     } else {
         rect = new Rectangle(Convert.ToInt32((rectSlider.Width / 2) - (sz.Width / 2)), Convert.ToInt32(sngSliderPos - sz.Height - (_SliderSize.Height / 2) - 3), Convert.ToInt32(sz.Width + 1), Convert.ToInt32(sz.Height + 2));
     }
     gp.AddRectangle(rect);
     pbr = new PathGradientBrush(gp);
     pbr.SurroundColors = new Color[] { Color.Transparent };
     if (this.BackColor == Color.Transparent) {
         pbr.CenterColor = this.Parent.BackColor;
     } else {
         pbr.CenterColor = this.BackColor;
     }
     g.FillRectangle(pbr, rect);
     rect.Y += 2;
     g.DrawString(_Value.ToString(), _FloatValueFont, new SolidBrush(_FloatValueFontColor), rect, sf);
     pbr.Dispose();
     gp.Dispose();
 }
        /// <summary>
        /// Draws a selected (mouse over) tab
        /// </summary>
        /// <param name="e"></param>
        public void DrawTabSelected(RibbonTabRenderEventArgs e)
        {
            if (e.Tab.Invisible)
                return;

            #region Office_2007

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007)
            {
                Rectangle outerR = Rectangle.FromLTRB(
                      e.Tab.TabBounds.Left,
                      e.Tab.TabBounds.Top,
                      e.Tab.TabBounds.Right - 1,
                      e.Tab.TabBounds.Bottom);
                Rectangle innerR = Rectangle.FromLTRB(
                     outerR.Left + 1,
                     outerR.Top + 1,
                     outerR.Right - 1,
                     outerR.Bottom);

                Rectangle glossyR = Rectangle.FromLTRB(
                     innerR.Left + 1,
                     innerR.Top + 1,
                     innerR.Right - 1,
                     innerR.Top + e.Tab.TabBounds.Height / 2);

                GraphicsPath outer = RoundRectangle(outerR, 3, Corners.NorthEast | Corners.NorthWest);
                GraphicsPath inner = RoundRectangle(innerR, 3, Corners.NorthEast | Corners.NorthWest);
                GraphicsPath glossy = RoundRectangle(glossyR, 3, Corners.NorthEast | Corners.NorthWest);

                using (Pen p = new Pen(ColorTable.TabBorder))
                {
                    e.Graphics.DrawPath(p, outer);
                }

                using (Pen p = new Pen(Color.FromArgb(200, Color.White)))
                {
                    e.Graphics.DrawPath(p, inner);
                }

                using (GraphicsPath radialPath = new GraphicsPath())
                {
                    radialPath.AddRectangle(innerR);
                    //radialPath.AddEllipse(innerR);
                    radialPath.CloseFigure();

                    PathGradientBrush gr = new PathGradientBrush(radialPath);
                    gr.CenterPoint = new PointF(
                         Convert.ToSingle(innerR.Left + innerR.Width / 2),
                         Convert.ToSingle(innerR.Top - 5));
                    gr.CenterColor = Color.Transparent;
                    gr.SurroundColors = new Color[] { ColorTable.TabSelectedGlow };

                    Blend blend = new Blend(3);
                    blend.Factors = new float[] { 0.0f, 0.9f, 0.0f };
                    blend.Positions = new float[] { 0.0f, 0.8f, 1.0f };

                    gr.Blend = blend;

                    e.Graphics.FillPath(gr, radialPath);

                    gr.Dispose();
                }
                using (SolidBrush b = new SolidBrush(Color.FromArgb(100, Color.White)))
                {
                    e.Graphics.FillPath(b, glossy);
                }

                outer.Dispose();
                inner.Dispose();
                glossy.Dispose();
            }

            #endregion

            #region Office_2010

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2010)
            {
                //background
                Rectangle outerR = Rectangle.FromLTRB(e.Tab.TabBounds.Left, e.Tab.TabBounds.Top, e.Tab.TabBounds.Right - 1, e.Tab.TabBounds.Bottom);
                Rectangle innerR = Rectangle.FromLTRB(outerR.Left + 1, outerR.Top + 1, outerR.Right - 1, outerR.Bottom);
                Rectangle glossyR = Rectangle.FromLTRB(innerR.Left + 1, innerR.Top + 1, innerR.Right - 1, innerR.Top + e.Tab.TabBounds.Height);

                GraphicsPath outer = RoundRectangle(outerR, 3, Corners.NorthEast | Corners.NorthWest);
                GraphicsPath inner = RoundRectangle(innerR, 3, Corners.NorthEast | Corners.NorthWest);
                GraphicsPath glossy = RoundRectangle(glossyR, 3, Corners.NorthEast | Corners.NorthWest);

                if (e.Tab.Contextual)
                {
                    using (GraphicsPath path = RoundRectangle(outerR, 6, Corners.North))
                    {

                     Color north = Color.FromArgb(200, e.Tab.Context.GlowColor);
                     Color centre = Color.FromArgb(40, e.Tab.Context.GlowColor);
                     Color south = Color.FromArgb(0, e.Tab.Context.GlowColor);
                        
                        //Tab background
                        using (LinearGradientBrush b = new LinearGradientBrush(
                                e.Tab.TabBounds, north, south, 90))
                        {
                            ColorBlend cb = new ColorBlend(3);
                            cb.Colors = new Color[] { north, centre, south };
                            cb.Positions = new float[] { 0f, .3f, 1f };
                            b.InterpolationColors = cb;
                    
                            e.Graphics.FillPath(b, path);
                        }
                    }
                }

                //Tab border
                using (GraphicsPath path = CreateTabPath_2010(e.Tab))
                {
                    using (Pen p = new Pen(ColorTable.TabSelectedBorder))
                    {
                        SmoothingMode sm = e.Graphics.SmoothingMode;
                        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        e.Graphics.DrawPath(p, path);
                        e.Graphics.SmoothingMode = sm;
                    }
                }

                //Interior shading and highlight
                using (GraphicsPath radialPath = new GraphicsPath())
                {
                    radialPath.AddRectangle(innerR);
                    radialPath.CloseFigure();

                    LinearGradientBrush b = new LinearGradientBrush(innerR, Color.FromArgb(50, Color.Gray), Color.FromArgb(80, Color.White), 90);

                    Blend blend = new Blend(3);
                    blend.Factors = new float[] { 0.0f, 0.6f, 1.0f };
                    blend.Positions = new float[] { 0.0f, 0.2f, 1.0f };

                    b.Blend = blend;

                    e.Graphics.FillPath(b, radialPath);

                    b.Dispose();
                }

                //Interior white line
                using (Pen p = new Pen(Color.FromArgb(200, Color.White)))
                {
                    e.Graphics.DrawPath(p, inner);
                }

				outer.Dispose();
				inner.Dispose();
				glossy.Dispose();
            }

            #endregion

            #region Office_2013

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2013)
            {
                //background
				Rectangle outerR = Rectangle.FromLTRB(e.Tab.TabBounds.Left, e.Tab.TabBounds.Top, e.Tab.TabBounds.Right - 1, e.Tab.TabBounds.Bottom);
				Rectangle innerR = Rectangle.FromLTRB(outerR.Left + 1, outerR.Top + 1, outerR.Right - 1, outerR.Bottom);
				//Rectangle glossyR = Rectangle.FromLTRB(innerR.Left + 1, innerR.Top + 1, innerR.Right - 1, innerR.Top + e.Tab.TabBounds.Height);

				//Tab border
				using(GraphicsPath path=CreateTabPath_2013(e.Tab))
				{
					using(Pen p=new Pen(ColorTable.TabSelectedBorder))
					{
						SmoothingMode sm=e.Graphics.SmoothingMode;
						e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;
						e.Graphics.DrawPath(p, path);
						e.Graphics.SmoothingMode=sm;
					}
				}

				//Interior shading and highlight
				using(GraphicsPath radialPath=new GraphicsPath())
				{
					radialPath.AddRectangle(innerR);
					radialPath.CloseFigure();

					LinearGradientBrush b=new LinearGradientBrush(innerR, Color.FromArgb(50, Color.Gray), Color.FromArgb(80, Color.White), 90);

					Blend blend=new Blend(3);
					blend.Factors=new float[] { 0.0f, 0.6f, 1.0f };
					blend.Positions=new float[] { 0.0f, 0.2f, 1.0f };

					b.Blend=blend;

					e.Graphics.FillPath(b, radialPath);

					b.Dispose();
				}

				//Interior white line
				using(GraphicsPath inner=FlatRectangle(innerR))
				{
					using(Pen p=new Pen(Color.FromArgb(200, Color.White)))
					{
						e.Graphics.DrawPath(p, inner);
					}
				}
            }

            #endregion
        }
Beispiel #25
0
		/// <summary>
		/// Paints background of the node.
		/// </summary>
		/// <param name="e">Context information.</param>
		protected virtual void PaintBackground(NodeRendererEventArgs e)
		{
			Graphics g = e.Graphics;
			bool mouseOver = e.Node.IsMouseOver;
			
			Region oldClip = g.Clip;
			Rectangle clipRect=e.NodeBounds;
			clipRect.Width--;
			clipRect.Height--;
			g.SetClip(clipRect, CombineMode.Replace);
			
			// Prepare colors
			NodeColors colors=new NodeColors();
			colors.NodeTopGradientBegin = m_ColorTable.NodeTopGradientBegin;
			colors.NodeTopGradientMiddle = m_ColorTable.NodeTopGradientMiddle;
			colors.NodeTopGradientEnd = m_ColorTable.NodeTopGradientEnd;
			colors.NodeTopGradientType = m_ColorTable.NodeTopGradientType;
			colors.NodeTopGradientAngle = m_ColorTable.NodeTopGradientAngle;
			colors.NodeBottomGradientBegin = m_ColorTable.NodeBottomGradientBegin;
			colors.NodeBottomGradientMiddle = m_ColorTable.NodeBottomGradientMiddle;
			colors.NodeBottomGradientEnd = m_ColorTable.NodeBottomGradientEnd;
			colors.NodeBottomGradientType = m_ColorTable.NodeBottomGradientType;
			colors.NodeBottomGradientAngle = m_ColorTable.NodeBottomGradientAngle;
			if(mouseOver)
			{
				colors.NodeTopGradientBegin = m_ColorTable.NodeMouseOverTopGradientBegin;
				colors.NodeTopGradientMiddle = m_ColorTable.NodeMouseOverTopGradientMiddle;
				colors.NodeTopGradientEnd = m_ColorTable.NodeMouseOverTopGradientEnd;
				colors.NodeTopGradientType = m_ColorTable.NodeMouseOverTopGradientType;
				colors.NodeTopGradientAngle = m_ColorTable.NodeMouseOverTopGradientAngle;
				colors.NodeBottomGradientBegin = m_ColorTable.NodeMouseOverBottomGradientBegin;
				colors.NodeBottomGradientMiddle = m_ColorTable.NodeMouseOverBottomGradientMiddle;
				colors.NodeBottomGradientEnd = m_ColorTable.NodeMouseOverBottomGradientEnd;
				colors.NodeBottomGradientType = m_ColorTable.NodeMouseOverBottomGradientType;
				colors.NodeBottomGradientAngle = m_ColorTable.NodeMouseOverBottomGradientAngle;
			}
			
			// Paint Background, Top Part
			Rectangle bounds=DisplayHelp.GetDrawRectangle(ElementStyleDisplay.GetBackgroundRectangle(e.Style,e.NodeBounds));
			GraphicsPath path;
			if (g.SmoothingMode == SmoothingMode.AntiAlias)
			{
				Rectangle r = bounds;
				r.Width--;
				path = ElementStyleDisplay.GetBackgroundPath(e.Style, r, eStyleBackgroundPathPart.TopHalf);
			}
			else
				path = ElementStyleDisplay.GetBackgroundPath(e.Style, bounds, eStyleBackgroundPathPart.TopHalf);
			path.CloseAllFigures();
			Rectangle backRect = bounds;
			backRect.Height = backRect.Height/2;
			PaintBackgroundPart(g, backRect, path, colors.NodeTopGradientBegin, colors.NodeTopGradientEnd,
			                    colors.NodeTopGradientType, colors.NodeTopGradientAngle);
			
			Rectangle ellipse = new Rectangle(bounds.X, bounds.Y - bounds.Height / 2, bounds.Width, bounds.Height);
			GraphicsPath pathFill=new GraphicsPath();
			pathFill.AddEllipse(ellipse);
			PathGradientBrush pathBrush = new PathGradientBrush(pathFill);
			pathBrush.CenterColor = colors.NodeTopGradientMiddle;
			pathBrush.SurroundColors = new Color[] { Color.Transparent };
			pathBrush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, bounds.Y);
			Blend blend = new Blend();
			blend.Factors = new float[] { 0f, .8f, 1f };
			blend.Positions = new float[] { .0f, .8f, 1f };
			pathBrush.Blend = blend;
			pathFill.Dispose();
			g.FillPath(pathBrush, path);
			pathBrush.Dispose();
			path.Dispose();
			
			// Bottom Part
			if (g.SmoothingMode == SmoothingMode.AntiAlias)
			{
				Rectangle r = bounds;
				r.Width--;
				path = ElementStyleDisplay.GetBackgroundPath(e.Style, r, eStyleBackgroundPathPart.BottomHalf);
			}
			else
				path = ElementStyleDisplay.GetBackgroundPath(e.Style, bounds, eStyleBackgroundPathPart.BottomHalf);
			path.CloseAllFigures();
			
			backRect.Y += backRect.Height;
			PaintBackgroundPart(g, backRect, path, colors.NodeBottomGradientBegin, colors.NodeBottomGradientEnd,
				colors.NodeBottomGradientType, colors.NodeBottomGradientAngle);
			
			ellipse = new Rectangle(bounds.X, bounds.Y + bounds.Height / 2 - 2, bounds.Width, bounds.Height + 4);
			pathFill=new GraphicsPath();
			pathFill.AddEllipse(ellipse);
			pathBrush = new PathGradientBrush(pathFill);
			pathBrush.CenterColor = colors.NodeBottomGradientMiddle;
			pathBrush.SurroundColors = new Color[] { Color.Transparent };
			pathBrush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, bounds.Bottom);
			blend = new Blend();
			blend.Factors = new float[] { 0f, .5f, 1f };
			blend.Positions = new float[] { .0f, .4f, 1f };
			pathBrush.Blend = blend;
			//path.Dispose();

			g.FillPath(pathBrush, path);
			pathBrush.Dispose();
			pathFill.Dispose();
			path.Dispose();
			
			if (oldClip != null)
				g.Clip = oldClip;
			else
				g.ResetClip();
			
		}
        void PaintView0(Graphics g)
        {
            var trianglePoints = new PointF[]{
                new PointF(this.ClientRectangle.Width/2,0),
                new PointF(0,this.ClientRectangle.Height),
                new PointF(this.ClientRectangle.Width,this.ClientRectangle.Height)};

            PathGradientBrush pgb = new PathGradientBrush(trianglePoints);

            var surroundColors = new Color[] { Color.Red, Color.Green, Color.Blue };

            pgb.SurroundColors = surroundColors;

            pgb.CenterColor = Color.Gray;
            //pgb.FocusScales = new PointF(0.3f, 0.8f);
            g.FillRectangle(pgb, this.ClientRectangle);

            pgb.Dispose();

            title = "Triangle Blend";
        }
		protected internal override void RenderShadow(Graphics graphics, IRender render)
		{
			if (DrawBackground)
			{
				if (Layer == null) return;
			
				//Use transformed path as shadows are not rotated
				GraphicsPath shadowPath = Geometry.ScalePath(TransformPath,1F,1F);    

				graphics.TranslateTransform(Layer.ShadowOffset.X ,Layer.ShadowOffset.Y);
				graphics.SmoothingMode = SmoothingMode.AntiAlias;

				//Draw soft shadows
				if (Layer.SoftShadows && StencilItem != null && ((StencilItem.Options & StencilItemOptions.SoftShadow) == StencilItemOptions.SoftShadow))
				{
					PathGradientBrush brush = new PathGradientBrush(shadowPath);

					//Calculate position factor based on 0.3 for 100 pixels
					//0.6 for 50 pixels, 0.15 for 200 pixels
					float factor = Convert.ToSingle(0.3 * (100 / Rectangle.Width));  

					//Set up the brush blend
					Blend blend = new Blend();
					blend.Positions = new float[] {0F,factor,1F};
					blend.Factors = new float[] {0F,0.8F,1F};
					brush.Blend = blend;

					brush.CenterColor = render.AdjustColor(Layer.ShadowColor,1,Opacity);
					//brush.CenterColor = Color.FromArgb(brush.CenterColor.A * 30 / 100,brush.CenterColor);
					brush.SurroundColors = new Color[] {Color.FromArgb(0, Layer.ShadowColor)};
					
					graphics.FillPath(brush, shadowPath);

					brush.Dispose();
				}
				else
				{
					SolidBrush shadowBrush = new SolidBrush(render.AdjustColor(Color.FromArgb(10,Layer.ShadowColor),1,Opacity));
					graphics.FillPath(shadowBrush,shadowPath);
				}

				//Restore graphics
				graphics.TranslateTransform(-Layer.ShadowOffset.X ,-Layer.ShadowOffset.Y);
				graphics.SmoothingMode = SmoothingMode;
			}
			else
			{
				if (DrawBorder) 
				{

					if (this.Layer == null) return;
			
					Layer layer = Layer;
					Pen shadowPen = new Pen(render.AdjustColor(layer.ShadowColor,BorderWidth,Opacity));
					GraphicsPath shadowPath = TransformPath;
			
					graphics.TranslateTransform(layer.ShadowOffset.X ,layer.ShadowOffset.Y);
			
					if (layer.SoftShadows)
					{
						graphics.CompositingQuality = CompositingQuality.HighQuality;
						graphics.SmoothingMode = SmoothingMode.HighQuality;
						graphics.DrawPath(shadowPen,shadowPath);
						graphics.CompositingQuality = render.CompositingQuality;
						graphics.SmoothingMode = SmoothingMode;
					}
					else
					{
						graphics.DrawPath(shadowPen,shadowPath);
					}

					//Restore graphics
					graphics.TranslateTransform(-layer.ShadowOffset.X ,-layer.ShadowOffset.Y);
				}
			}
		}
        private void drawPathGradient(Rectangle rDmn, IntPtr hdc)
        {
            Graphics g = Graphics.FromHdc(hdc);
            GraphicsPath gP = new GraphicsPath();
            gP.AddRectangle(rDmn);
            PathGradientBrush pGp = new PathGradientBrush(gP);

            float o = _fOpacity * 255;
            Color c1 = Color.FromArgb((int)o, _oGradientStartColor);
            Color c2 = Color.FromArgb((int)o, _oGradientEndColor);

            switch (_eGradientStyle)
            {
                case GradientStyle.BlendTriangular:
                    pGp.CenterPoint = new PointF(rDmn.Width / 2, rDmn.Height / 2);
                    pGp.CenterColor = c2;
                    pGp.SurroundColors = new Color[] { c1 };
                    g.FillPath(pGp, gP);
                    break;
                case GradientStyle.FloatingBoxed:
                    pGp.FocusScales = new PointF(0f, 0f);
                    pGp.CenterColor = c2;
                    pGp.SurroundColors = new Color[] { c1 };
                    Blend bP = new Blend();
                    bP.Positions = new float[] { 0f, .2f, .4f, .6f, .8f, 1f };
                    bP.Factors = new float[] { .2f, .5f, .2f, .5f, .2f, .5f };
                    pGp.Blend = bP;
                    g.FillPath(pGp, gP);
                    break;
            }
            pGp.Dispose();
            gP.Dispose();
            g.Dispose();
        }
Beispiel #29
0
 public void gradient(Point[] points, PathGradientBrush pgbrush, Triangle tre, GraphicsPath brushPath)
 {
     Color[] mySurroundColor = { tre.v1.currColor, tre.v2.currColor, tre.v3.currColor};
     pgbrush.SurroundColors = mySurroundColor;
     int averageR = (tre.v1.currColor.R + tre.v2.currColor.R + tre.v3.currColor.R) / 3;
     int averageG = (tre.v1.currColor.G + tre.v2.currColor.G + tre.v3.currColor.G) / 3;
     int averageB = (tre.v1.currColor.B + tre.v2.currColor.B + tre.v3.currColor.B) / 3;
     Color centerCol = Color.FromArgb((byte) averageR, (byte)averageG, (byte)averageB);
     pgbrush.CenterColor = centerCol;
     pgbrush.SetBlendTriangularShape(0.7f, 0.7f);
     graphics.FillPolygon(pgbrush, points);
     pgbrush.Dispose();
 }
Beispiel #30
0
        protected override void PaintState(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r, bool isMouseDown)
        {
            if (r.IsEmpty || !IsItemEnabled(button, pa) || r.Width == 0 || r.Height == 0)
                return;

            RibbonTabItem tab = button as RibbonTabItem;
            if (tab == null || IsOnMenu(button, pa))
            {
                base.PaintState(button, pa, image, r, isMouseDown);
                return;
            }

            bool isOnMenu = pa.IsOnMenu;
            Office2007RibbonTabItemColorTable tabColorTable = GetColorTable(tab);
            if (tabColorTable == null)
                return;
            bool ribbonExpanded = pa.ControlExpanded;

            Office2007RibbonTabItemStateColorTable stateColors = GetStateColorTable(tabColorTable, tab, ribbonExpanded);

            if (stateColors == null)
                return;

            Graphics g = pa.Graphics;
            int cornerSize = tabColorTable.CornerSize;
            Region oldClip = g.Clip;
            try
            {
                Rectangle rClip = r;
                rClip.Inflate(1, 0);
                g.SetClip(rClip, CombineMode.Replace);

                if (stateColors != null)
                {
                    eDotNetBarStyle effectiveStyle = button.EffectiveStyle;
                    using (GraphicsPath path = GetTabPath(r, cornerSize, true, effectiveStyle))
                    {
                        DisplayHelp.FillPath(g, path, stateColors.Background);
                        DisplayHelp.DrawGradientPathBorder(g, path, stateColors.OuterBorder, 1);
                    }
                    if (effectiveStyle != eDotNetBarStyle.Metro && tab.Checked && ribbonExpanded && tab.RenderTabState /*|| tab.IsMouseOver*/)
                    {
                        SmoothingMode sm = g.SmoothingMode;
                        g.SmoothingMode = SmoothingMode.Default;

                        if (this.ColorTable.RibbonControl.TabsBackground.Start.GetBrightness() > .5 && !stateColors.OuterBorder.IsEmpty)
                        {
                            using (GraphicsPath path = new GraphicsPath())
                            {
                                path.AddRectangle(new Rectangle(r.Right - 1, r.Y + cornerSize + 1, 1, r.Height - cornerSize - 3));
                                DisplayHelp.FillPath(g, path, Color.FromArgb(96, stateColors.OuterBorder.Start), Color.FromArgb(32, stateColors.OuterBorder.End), 90);
                            }
                            using (GraphicsPath path = new GraphicsPath())
                            {
                                path.AddRectangle(new Rectangle(r.X + 1, r.Y + cornerSize + 1, 1, r.Height - cornerSize - 3));
                                DisplayHelp.FillPath(g, path, Color.FromArgb(32, stateColors.OuterBorder.Start), Color.FromArgb(8, stateColors.OuterBorder.End), 90);
                            }
                        }
                        g.SmoothingMode = sm;
                    }

                    Rectangle r1 = r;
                    r1.Inflate(-1, 0);
                    r1.Height--;
                    r1.Y++;
                    using (GraphicsPath path = GetTabPath(r1, cornerSize, true, effectiveStyle))
                    {
                        DisplayHelp.DrawGradientPathBorder(g, path, stateColors.InnerBorder, 1);
                    }

                    if (tab.Checked && ribbonExpanded && tab.RenderTabState)
                    {
                        using (SolidBrush brush = new SolidBrush(stateColors.InnerBorder.Start))
                        {
                            SmoothingMode sm = g.SmoothingMode;
                            g.SmoothingMode = SmoothingMode.None;
                            g.FillRectangle(brush, new Rectangle(r1.X + cornerSize, r1.Y + 1, r1.Width - cornerSize * 2, 2));
                            g.SmoothingMode = sm;
                        }
                    }

                    float topSplit = .6f;
                    float bottomSplit = .4f;

                    Rectangle fillRectangle = r;
                    Rectangle backRect = new Rectangle(fillRectangle.X, fillRectangle.Y + (int)(fillRectangle.Height * topSplit), fillRectangle.Width, (int)(fillRectangle.Height * bottomSplit));

                    if (!stateColors.BackgroundHighlight.IsEmpty)
                    {
                        Rectangle ellipse = new Rectangle(backRect.X, backRect.Y, fillRectangle.Width, fillRectangle.Height);
                        GraphicsPath path = new GraphicsPath();
                        path.AddEllipse(ellipse);
                        PathGradientBrush brush = new PathGradientBrush(path);
                        brush.CenterColor = stateColors.BackgroundHighlight.Start;
                        brush.SurroundColors = new Color[] { stateColors.BackgroundHighlight.End };
                        brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom + 2);
                        Blend blend = new Blend();
                        blend.Factors = new float[] { 0f, .8f, 1f };
                        blend.Positions = new float[] { .0f, .55f, 1f };
                        brush.Blend = blend;
                        g.FillRectangle(brush, backRect);
                        brush.Dispose();
                        path.Dispose();
                    }
                }

                if (tab.ReducedSize && !tab.Checked && !tab.IsMouseOver && tabColorTable != null && tabColorTable.Selected != null)
                {
                    Color c = this.ColorTable.RibbonControl.OuterBorder.Start;
                    if (!c.IsEmpty)
                        DisplayHelp.DrawGradientLine(g, new Point(r.Right - 1, r.Y), new Point(r.Right - 1, r.Bottom - 1),
                            Color.Transparent, c, 90, 1, new float[] { 0, .8f, 1f }, new float[] { 0, .50f, 1f });
                }

                g.Clip = oldClip;
            }
            finally
            {
                if (oldClip != null) oldClip.Dispose();
            }
        }
Beispiel #31
-1
		private void PathGradient_Paint(object sender, PaintEventArgs e)
		{
			GraphicsPath path = new GraphicsPath();
			int size = 150;
			path.AddEllipse(10, 10, size, size);
			
			PathGradientBrush brush = new PathGradientBrush(path);
			brush.WrapMode = WrapMode.Tile;
			brush.SurroundColors = new Color[] { Color.White };
			brush.CenterColor = Color.Violet;
			e.Graphics.FillRectangle(brush, 10, 10, size, size);
			
			path.Dispose();
			brush.Dispose();
        
        
		}