Beispiel #1
0
 protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
 {
     GraphicsPath grPath = new GraphicsPath();
     grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
     this.Region = new System.Drawing.Region(grPath);
     base.OnPaint(e);
 }
Beispiel #2
0
 protected override void OnResize(EventArgs e)
 {
     using (var path = new GraphicsPath())
     {
         path.AddEllipse(new Rectangle(2, 2, this.Width - 4, this.Height - 4));
         this.Region = new Region(path);
     }
     base.OnResize(e);
 }
 protected override void OnResize(EventArgs e)
 {
     base.OnResize(e);
     using (var gp = new GraphicsPath())
     {
         gp.AddEllipse(new Rectangle(0, 0, this.Width - 1, this.Height - 1));
         this.Region = new Region(gp);
     }
 }
Beispiel #4
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            //remove all previous shapes if GraphicPath


            //check for mouse left button clicked
            if (e.Button == MouseButtons.Left)
            {
                path.Reset();
                switch (tool)
                {
                case Tool.PEN:
                    cur = e.Location;
                    g.DrawLine(pen, prev, cur);
                    prev = cur;
                    break;

                case Tool.LINE:
                    cur = e.Location;
                    path.AddLine(prev, cur);
                    break;

                case Tool.RECTANGLE:
                    cur = e.Location;
                    if (cur.X < prev.X && cur.Y < prev.Y)
                    {
                        path.AddRectangle(new Rectangle(cur.X, cur.Y, Math.Abs(cur.X - prev.X), Math.Abs(cur.Y - prev.Y)));
                    }

                    else if (cur.Y > prev.Y && cur.X < prev.X)
                    {
                        path.AddRectangle(new Rectangle(cur.X, prev.Y, prev.X - cur.X, cur.Y - prev.Y));
                    }

                    else if (cur.X > prev.X && cur.Y < prev.Y)
                    {
                        path.AddRectangle(new Rectangle(prev.X, cur.Y, cur.X - prev.X, prev.Y - cur.Y));
                    }

                    else
                    {
                        path.AddRectangle(new Rectangle(prev.X, prev.Y, Math.Abs(cur.X - prev.X), Math.Abs(cur.Y - prev.Y)));
                    }
                    break;

                case Tool.CIRCLE:
                    cur = e.Location;
                    if (flag_circle_bool)
                    {
                        flag_circle_int = cur.Y;
                    }
                    path.AddEllipse(new Rectangle(prev.X, cur.Y, cur.X - prev.X, cur.Y - prev.Y));
                    flag_circle_bool = false;
                    break;

                case Tool.ERASE:
                    cur = e.Location;
                    g.DrawLine(new Pen(Color.White, pen.Width), prev, cur);
                    prev = cur;
                    break;

                case Tool.TRIANGLE:
                    cur = e.Location;
                    Point[] points = new Point[] { new Point(prev.X, prev.Y), new Point(prev.X - (cur.X - prev.X), cur.Y), cur };
                    path.AddPolygon(points);
                    break;
                }
            }
            pictureBox1.Refresh();
        }
Beispiel #5
0
        private void PaintText(Graphics g, Rectangle rectDraw, bool bRtl)
        {
            if (string.IsNullOrEmpty(m_strText))
            {
                return;
            }

            Font  f     = (FontUtil.DefaultFont ?? this.Font);
            Color clrFG = UIUtil.ColorToGrayscale(this.ForeColor);
            Color clrBG = Color.FromArgb(clrFG.ToArgb() ^ 0x20FFFFFF);

            int dx = rectDraw.X;
            int dy = rectDraw.Y;
            int dw = rectDraw.Width;
            int dh = rectDraw.Height;

            if (!NativeLib.IsUnix() || !UIUtil.IsDarkColor(clrFG))
            {
                Rectangle rectGlow = rectDraw;
                rectGlow.Width = TextRenderer.MeasureText(g, m_strText, f).Width;
                rectGlow.X     = ((dw - rectGlow.Width) / 2) + dx;

                // Instead of an ellipse, Mono draws a circle
                if (NativeLib.IsUnix())
                {
                    rectGlow.Inflate(rectGlow.Width * 2, rectGlow.Height * 2);
                }
                else
                {
                    rectGlow.Inflate(rectGlow.Width / 2, rectGlow.Height / 2);
                }

                using (GraphicsPath gpGlow = new GraphicsPath())
                {
                    gpGlow.AddEllipse(rectGlow);

                    using (PathGradientBrush pgbGlow = new PathGradientBrush(gpGlow))
                    {
                        pgbGlow.CenterPoint = new PointF((dw / 2.0f) + dx,
                                                         (dh / 2.0f) + dy);
                        pgbGlow.CenterColor    = clrBG;
                        pgbGlow.SurroundColors = new Color[] { Color.Transparent };

                        Region rgOrgClip = g.Clip;
                        g.SetClip(rectDraw);
                        g.FillPath(pgbGlow, gpGlow);
                        g.Clip = rgOrgClip;
                    }
                }
            }

            // With ClearType on, text drawn using Graphics.DrawString
            // looks better than TextRenderer.DrawText;
            // https://sourceforge.net/p/keepass/discussion/329220/thread/06ef4466/
            // TextFormatFlags tff = (TextFormatFlags.HorizontalCenter | TextFormatFlags.SingleLine |
            //	TextFormatFlags.VerticalCenter);
            // TextRenderer.DrawText(g, m_strText, f, rectDraw, clrFG, tff);

            using (SolidBrush br = new SolidBrush(clrFG))
            {
                StringFormatFlags sff = (StringFormatFlags.FitBlackBox |
                                         StringFormatFlags.NoClip);
                if (bRtl)
                {
                    sff |= StringFormatFlags.DirectionRightToLeft;
                }

                using (StringFormat sf = new StringFormat(sff))
                {
                    sf.Alignment     = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;

                    RectangleF rf = new RectangleF(dx, dy, dw, dh);
                    g.DrawString(m_strText, f, br, rf, sf);
                }
            }
        }
        /// <summary>
        /// Probably a more efficient way, but this gives the easiest testable visible results
        /// </summary>
        /// <param name="clientRectangle"></param>
        /// <returns></returns>
        private Bitmap DrawShadowBitmap(Rectangle clientRectangle)
        {
            int extraWidth = (_shadowValues.ExtraWidth > 0) ? _shadowValues.ExtraWidth : 0;
            int w          = clientRectangle.Width + extraWidth * 2;
            int h          = clientRectangle.Height + extraWidth * 2;

            float  blur       = (float)(_shadowValues.BlurDistance / 100.0 * Math.Abs(_shadowValues.ExtraWidth));
            float  solidW     = clientRectangle.Width + blur * 2;
            float  solidH     = clientRectangle.Height + blur * 2;
            float  blurOffset = _shadowValues.ExtraWidth - blur;
            Bitmap bitmap     = new Bitmap(w, h);

            bitmap.MakeTransparent();
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                // fill background
                //g.FillRectangle(Brushes.Magenta, 0,0,w,h);
                // +1 to fill the gap
                g.FillRectangle(new SolidBrush(_shadowValues.Colour),
                                blurOffset, blurOffset, solidW + 1, solidH + 1);

                // four dir gradient
                if (blurOffset > 0)
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(new PointF(0, 0), new PointF(blurOffset, 0),
                                                                               Color.Transparent, _shadowValues.Colour))
                    {
                        // Left
                        g.FillRectangle(brush, 0, blurOffset, blurOffset, solidH);

                        // Top
                        brush.RotateTransform(90);
                        g.FillRectangle(brush, blurOffset, 0, solidW, blurOffset);

                        // Right
                        // make sure pattern is correct
                        brush.ResetTransform();
                        brush.TranslateTransform(w % blurOffset, h % blurOffset);

                        brush.RotateTransform(180);
                        g.FillRectangle(brush, w - blurOffset, blurOffset, blurOffset, solidH);
                        // Bottom
                        brush.RotateTransform(90);
                        g.FillRectangle(brush, blurOffset, h - blurOffset, solidW, blurOffset);
                    }


                    // four corner
                    using (GraphicsPath gp = new GraphicsPath())
                        using (Matrix matrix = new Matrix())
                        {
                            gp.AddEllipse(0, 0, blurOffset * 2, blurOffset * 2);
                            using (PathGradientBrush pgb = new PathGradientBrush(gp)
                            {
                                CenterColor = _shadowValues.Colour,
                                SurroundColors = new[] { Color.Transparent },
                                CenterPoint = new PointF(blurOffset, blurOffset)
                            })
                            {
                                // left-Top
                                g.FillPie(pgb, 0, 0, blurOffset * 2, blurOffset * 2, 180, 90);

                                // right-Top
                                matrix.Translate(w - blurOffset * 2, 0);

                                pgb.Transform = matrix;
                                //pgb.Transform.Translate(w-blur*2, 0);
                                g.FillPie(pgb, w - blurOffset * 2, 0, blurOffset * 2, blurOffset * 2, 270, 90);

                                // right-Bottom
                                matrix.Translate(0, h - blurOffset * 2);
                                pgb.Transform = matrix;
                                g.FillPie(pgb, w - blurOffset * 2, h - blurOffset * 2, blurOffset * 2, blurOffset * 2, 0, 90);

                                // left-Bottom
                                matrix.Reset();
                                matrix.Translate(0, h - blurOffset * 2);
                                pgb.Transform = matrix;
                                g.FillPie(pgb, 0, h - blurOffset * 2, blurOffset * 2, blurOffset * 2, 90, 90);
                            }
                        }
                }
            }

            //
            return(bitmap);
        }
Beispiel #7
0
        /// <summary>
        /// Repaints the form with cool background and stuff.
        /// </summary>
        /// <param name="graph">The graphics object to paint to, the element will be drawn to 0, 0.</param>
        public virtual void Paint(Graphics graph)
        {
            // Sets up the colors to use
            Pen   outlinePen     = new Pen(SymbologyGlobal.ColorFromHsl(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 0.6 * Highlight), 1.75F);
            Color gradientTop    = SymbologyGlobal.ColorFromHsl(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 0.7 * Highlight);
            Color gradientBottom = SymbologyGlobal.ColorFromHsl(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 1.0 * Highlight);

            // The path used for drop shadows
            GraphicsPath shadowPath = new GraphicsPath();
            ColorBlend   colorBlend = new ColorBlend(3)
            {
                Colors    = new[] { Color.Transparent, Color.FromArgb(180, Color.DarkGray), Color.FromArgb(180, Color.DimGray) },
                Positions = new[] { 0f, 0.125f, 1f }
            };

            // Draws Rectangular Shapes
            if (Shape == ModelShape.Rectangle)
            {
                // Draws the shadow
                shadowPath.AddPath(GetRoundedRect(new Rectangle(5, 5, Width, Height), 10), true);
                PathGradientBrush shadowBrush = new PathGradientBrush(shadowPath)
                {
                    WrapMode            = WrapMode.Clamp,
                    InterpolationColors = colorBlend
                };
                graph.FillPath(shadowBrush, shadowPath);

                // Draws the basic shape
                Rectangle           fillRectange = new Rectangle(0, 0, Width - 5, Height - 5);
                GraphicsPath        fillArea     = GetRoundedRect(fillRectange, 5);
                LinearGradientBrush myBrush      = new LinearGradientBrush(fillRectange, gradientBottom, gradientTop, LinearGradientMode.Vertical);
                graph.FillPath(myBrush, fillArea);
                graph.DrawPath(outlinePen, fillArea);

                // Draws the status light
                DrawStatusLight(graph);

                // Draws the text
                SizeF      textSize = graph.MeasureString(Name, Font, Width);
                RectangleF textRect;
                if ((textSize.Width < Width) || (textSize.Height < Height))
                {
                    textRect = new RectangleF((Width - textSize.Width) / 2, (Height - textSize.Height) / 2, textSize.Width, textSize.Height);
                }
                else
                {
                    textRect = new RectangleF(0, (Height - textSize.Height) / 2, Width, textSize.Height);
                }
                graph.DrawString(Name, Font, new SolidBrush(Color.FromArgb(50, Color.Black)), textRect);
                textRect.X = textRect.X - 1;
                textRect.Y = textRect.Y - 1;
                graph.DrawString(Name, Font, Brushes.Black, textRect);

                // Garbage collection
                fillArea.Dispose();
                myBrush.Dispose();
            }

            // Draws Ellipse Shapes
            if (Shape == ModelShape.Ellipse)
            {
                // Draws the shadow
                shadowPath.AddEllipse(0, 5, Width + 5, Height);
                PathGradientBrush shadowBrush = new PathGradientBrush(shadowPath)
                {
                    WrapMode            = WrapMode.Clamp,
                    InterpolationColors = colorBlend
                };
                graph.FillPath(shadowBrush, shadowPath);

                // Draws the Ellipse
                Rectangle           fillArea = new Rectangle(0, 0, Width, Height);
                LinearGradientBrush myBrush  = new LinearGradientBrush(fillArea, gradientBottom, gradientTop, LinearGradientMode.Vertical);
                graph.FillEllipse(myBrush, 1, 1, Width - 5, Height - 5);
                graph.DrawEllipse(outlinePen, 1, 1, Width - 5, Height - 5);

                // Draws the text
                SizeF      textSize = graph.MeasureString(Name, Font, Width);
                RectangleF textRect;
                if ((textSize.Width < Width) || (textSize.Height < Height))
                {
                    textRect = new RectangleF((Width - textSize.Width) / 2, (Height - textSize.Height) / 2, textSize.Width, textSize.Height);
                }
                else
                {
                    textRect = new RectangleF(0, (Height - textSize.Height) / 2, Width, textSize.Height);
                }
                graph.DrawString(Name, Font, new SolidBrush(Color.FromArgb(50, Color.Black)), textRect);
                textRect.X = textRect.X - 1;
                textRect.Y = textRect.Y - 1;
                graph.DrawString(Name, Font, Brushes.Black, textRect);

                // Garbage collection
                myBrush.Dispose();
            }

            // Draws Triangular Shapes
            if (Shape == ModelShape.Triangle)
            {
                // Draws the shadow
                Point[] ptShadow = new Point[4];
                ptShadow[0] = new Point(5, 5);
                ptShadow[1] = new Point(Width + 5, ((Height - 5) / 2) + 5);
                ptShadow[2] = new Point(5, Height + 2);
                ptShadow[3] = new Point(5, 5);
                shadowPath.AddLines(ptShadow);
                PathGradientBrush shadowBrush = new PathGradientBrush(shadowPath)
                {
                    WrapMode            = WrapMode.Clamp,
                    InterpolationColors = colorBlend
                };
                graph.FillPath(shadowBrush, shadowPath);

                // Draws the shape
                Point[] pt = new Point[4];
                pt[0] = new Point(0, 0);
                pt[1] = new Point(Width - 5, (Height - 5) / 2);
                pt[2] = new Point(0, Height - 5);
                pt[3] = new Point(0, 0);
                GraphicsPath myPath = new GraphicsPath();
                myPath.AddLines(pt);
                Rectangle           fillArea = new Rectangle(1, 1, Width - 5, Height - 5);
                LinearGradientBrush myBrush  = new LinearGradientBrush(fillArea, gradientBottom, gradientTop, LinearGradientMode.Vertical);
                graph.FillPath(myBrush, myPath);
                graph.DrawPath(outlinePen, myPath);

                // Draws the text
                SizeF      textSize = graph.MeasureString(Name, Font, Width);
                RectangleF textRect;
                if ((textSize.Width < Width) || (textSize.Height < Height))
                {
                    textRect = new RectangleF((Width - textSize.Width) / 2, (Height - textSize.Height) / 2, textSize.Width, textSize.Height);
                }
                else
                {
                    textRect = new RectangleF(0, (Height - textSize.Height) / 2, Width, textSize.Height);
                }
                graph.DrawString(Name, Font, Brushes.Black, textRect);

                // Garbage collection
                myBrush.Dispose();
            }

            // Garbage collection
            shadowPath.Dispose();
            outlinePen.Dispose();
        }
 protected override void AddShapePath(GraphicsPath graphicsPath, Rectangle rect)
 {
     graphicsPath.AddEllipse(rect);
 }
Beispiel #9
0
	public static void Main (string[] args)
	{
		Bitmap	bmp = new Bitmap (600, 600);
		Graphics gr = Graphics.FromImage (bmp);
		Rectangle rect = new Rectangle (20, 20, 100, 100);

		PointF[] polygon_pnts = {new PointF(150.0F,  150.0F),
			new PointF(200.0F,  125.0F), new PointF(300.0F, 105.0F),
			new PointF(350.0F, 150.0F), new PointF(400.0F, 200.0F),
			new PointF(450.0F, 300.0F), new PointF(350.0F, 350.0F) };


		// Default Display
    		gr.DrawRectangle (Pens.Red, rect);
    		gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Red, 50, 50);
    		gr.DrawArc (Pens.Red, 30, 30, 60, 60, 0, 180);
    		gr.DrawPolygon (Pens.Red, polygon_pnts);

    		// Point
    		gr.PageUnit = GraphicsUnit.Point;
    		gr.DrawRectangle (Pens.Yellow, rect);
    		gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Yellow, 50, 50);
    		gr.DrawArc (Pens.Yellow, 30, 30, 60, 60, 0, 180);
    		gr.DrawPolygon (Pens.Yellow, polygon_pnts);

    		// Document
    		gr.PageUnit = GraphicsUnit.Document;
    		gr.DrawRectangle (Pens.Pink, rect);
    		gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Pink, 50, 50);
    		gr.DrawArc (Pens.Pink, 30, 30, 60, 60, 0, 180);
    		gr.DrawPolygon (Pens.Pink, polygon_pnts);

    		// Inc
    		gr.PageUnit = GraphicsUnit.Inch;
    		gr.DrawRectangle (Pens.Blue, 3f, 1f, 1f, 1f);
    		gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Blue, 0.7f, 0.7f);
    		gr.DrawArc (Pens.Blue, 3f, 3f, 1f, 1f, 0, 180);


       		bmp.Save ("units1.bmp");
       		bmp.Dispose ();
       		gr.Dispose ();

       		bmp = new Bitmap (600, 600);
		gr = Graphics.FromImage (bmp);

		GraphicsPath graphPath = new GraphicsPath();
    		graphPath.AddEllipse (0, 80, 100, 200);

		// Default Display
    		gr.DrawBezier (Pens.Red, new Point (10, 10), new Point (20, 10),
    			new Point (35, 50), new Point (50, 10));

    		gr.DrawEllipse (Pens.Red, 10, 50, 30, 50);
    		gr.DrawPath (Pens.Red, graphPath);
    		gr.DrawPie (Pens.Red, 150, 20, 60, 60, 100, 140);
    		gr.DrawCurve (Pens.Red, polygon_pnts, 2, 4, 0.5f);


    		// Point
    		gr.PageUnit = GraphicsUnit.Display;
    		gr.PageUnit = GraphicsUnit.Point;
    		gr.DrawBezier (Pens.Pink, new Point (10, 10), new Point (20, 10),
    			new Point (35, 50), new Point (50, 10));
    		gr.DrawCurve (Pens.Pink, polygon_pnts, 2, 4, 0.5f);

    		gr.DrawEllipse (Pens.Pink, 10, 50, 30, 50);
    		gr.DrawPath (Pens.Pink, graphPath);
    		gr.DrawPie (Pens.Pink, 150, 20, 60, 60, 100, 140);

    		// Document
    		gr.PageUnit = GraphicsUnit.Document;
    		gr.DrawBezier (Pens.Yellow, new Point (10, 10), new Point (20, 10),
    			new Point (35, 50), new Point (50, 10));

    		gr.DrawEllipse (Pens.Yellow, 10, 50, 30, 50);
    		gr.DrawPath (Pens.Yellow, graphPath);
    		gr.DrawPie (Pens.Yellow, 150, 20, 60, 60, 100, 140);
    		gr.DrawCurve (Pens.Yellow, polygon_pnts, 2, 4, 0.5f);

    		// Inc
    		gr.PageUnit = GraphicsUnit.Inch;
    		gr.DrawBezier (Pens.Blue, new Point (10, 10), new Point (20, 10),
    			new Point (35, 50), new Point (50, 10));

    		gr.DrawEllipse (Pens.Blue, 10, 50, 30, 50);
    		gr.DrawPath (Pens.Blue, graphPath);
    		gr.DrawPie (Pens.Blue, 150, 20, 60, 60, 100, 140);
    		gr.DrawCurve (Pens.Blue, polygon_pnts, 2, 4, 0.5f);

		bmp.Save ("units2.bmp");
        }
    public bool IsFit(Point[] points)
    {
        // Note: rigorously calculating distance(point,ellipse) is very hard...
        // overlay the regions and compare the areas, for now.
        using (GraphicsPath polygp = new GraphicsPath())
        using (GraphicsPath elligp = new GraphicsPath())
        using (Matrix m = new Matrix())
        {
            // Set up gp for stroke.
            polygp.AddPolygon(points);

            // Set up gp for ellipse.
            elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);

            m.Translate((float)cx,(float)cy);
            m.Rotate((float)th);
            elligp.Transform(m);

            // Prepare regions for area-calculation.
            using (Region xor = new Region(elligp))
            using (Region isc = new Region(elligp))
            {
                xor.Xor(polygp);
                isc.Intersect(polygp);

                float badarea = Geometry.CalculateArea(xor);
                float iscarea = Geometry.CalculateArea(isc);
                float ratio = iscarea/badarea;

                //heuristic: 10.0 seems about right.
                return (ratio > 10f);
            }
        }
    }
Beispiel #11
0
        //重绘时
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            base.OnPaintBackground(e);
            Graphics g = e.Graphics;
            //RadioButton的绘画范围
            Rectangle radioButtonrect;
            //文字绘画范围
            Rectangle textRect;

            //给CheckButtom与文字的绘画范围赋值
            CalculateRect(out radioButtonrect, out textRect);
            //抗锯齿的呈现
            g.SmoothingMode = SmoothingMode.AntiAlias;

            //取得当前需要绘画的图像
            Bitmap btm = null;
            //当前无图像时绘画的颜色变量
            Color borderColor;
            Color innerBorderColor;
            Color checkColor;
            bool  hover = false;

            //启用状态时
            if (Enabled)
            {
                switch (ControlState)
                {
                case ControlState.Hover:
                    borderColor      = _baseColor;
                    innerBorderColor = _baseColor;
                    checkColor       = GetColor(_baseColor, 0, 35, 24, 9);
                    btm   = Checked ? (Bitmap)SelectedMouseBack : (Bitmap)MouseBack;
                    hover = true;
                    break;

                case ControlState.Pressed:
                    borderColor      = _baseColor;
                    innerBorderColor = GetColor(_baseColor, 0, -13, -8, -3);
                    checkColor       = GetColor(_baseColor, 0, -35, -24, -9);
                    btm   = Checked ? (Bitmap)SelectedDownBack : (Bitmap)DownBack;
                    hover = true;
                    break;

                default:
                    borderColor      = _baseColor;
                    innerBorderColor = Color.Empty;
                    checkColor       = _baseColor;
                    btm = Checked ? (Bitmap)SelectedNormlBack : (Bitmap)NormlBack;
                    break;
                }
            }
            else //禁用状态时
            {
                borderColor      = SystemColors.ControlDark;
                innerBorderColor = SystemColors.ControlDark;
                checkColor       = SystemColors.ControlDark;
                btm = Checked ? (Bitmap)SelectedNormlBack : (Bitmap)NormlBack;
            }

            if (btm == null)
            {
                using (SolidBrush brush = new SolidBrush(Color.White))
                {
                    g.FillEllipse(brush, radioButtonrect);
                }

                if (hover)
                {
                    using (Pen pen = new Pen(innerBorderColor, 2F))
                    {
                        g.DrawEllipse(pen, radioButtonrect);
                    }
                }

                if (Checked)
                {
                    radioButtonrect.Inflate(-2, -2);
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        path.AddEllipse(radioButtonrect);
                        using (PathGradientBrush brush = new PathGradientBrush(path))
                        {
                            brush.CenterColor    = checkColor;
                            brush.SurroundColors = new Color[] { Color.White };
                            Blend blend = new Blend();
                            blend.Positions = new float[] { 0f, 0.4f, 1f };
                            blend.Factors   = new float[] { 0f, 0.4f, 1f };
                            brush.Blend     = blend;
                            g.FillEllipse(brush, radioButtonrect);
                        }
                    }
                    radioButtonrect.Inflate(2, 2);
                }

                using (Pen pen = new Pen(borderColor))
                {
                    g.DrawEllipse(pen, radioButtonrect);
                }
            }
            else
            {
                //画图像
                g.DrawImage(btm, radioButtonrect);
            }

            //画字体
            Color textColor = Enabled ? ForeColor : SystemColors.GrayText;

            //是否绘画发光字体
            if (LightEffect)
            {
                Image imgText = SkinTools.ImageLightEffect(Text, Font, textColor, LightEffectBack, LightEffectWidth);
                g.DrawImage(imgText, textRect);
            }
            else
            {
                TextRenderer.DrawText(
                    g,
                    Text,
                    Font,
                    textRect,
                    textColor,
                    GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes));
            }
        }
Beispiel #12
0
        /// <summary>
        /// Control 클래스의 OnPaint 메서드 재정의하여 Graphics 객체 얻기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GDIPlusForm_Paint(object sender, PaintEventArgs e)
        {
#if PEN
            Pen pen = new Pen(Color.Blue, 3);
            e.Graphics.DrawLine(pen, 10, 10, 200, 10);

            pen.Color = Color.LightSalmon;

            for (int i = 1; i <= 5; i++)
            {
                pen.Width = i;
                e.Graphics.DrawLine(pen, 10, 50 + i * 10, 200, 50 + i * 10);
            }
            Brush brush = new HatchBrush(HatchStyle.Sphere, Color.Red, Color.LightGreen);
            pen = new Pen(brush, 20);
            e.Graphics.DrawEllipse(pen, 10, 150, 200, 100);
#elif DASHSTYLE
            Pen pen = new Pen(Color.Black, 3);

            pen.DashStyle = DashStyle.Solid;
            e.Graphics.DrawLine(pen, 10, 10, 200, 10);

            pen.DashStyle = DashStyle.Dot;
            e.Graphics.DrawLine(pen, 10, 30, 200, 30);

            pen.DashStyle = DashStyle.Dash;
            e.Graphics.DrawLine(pen, 10, 50, 200, 50);

            pen.DashStyle = DashStyle.DashDot;
            e.Graphics.DrawLine(pen, 10, 70, 200, 70);

            pen.DashStyle = DashStyle.DashDotDot;
            e.Graphics.DrawLine(pen, 10, 90, 200, 90);

            pen.DashStyle = DashStyle.Dash;
            for (int i = 1; i < 10; i += 2)
            {
                pen.Width = i;
                e.Graphics.DrawLine(pen, 10, 120 + i * 10, 200, 120 + i * 10);
            }

            pen.Width       = 5;
            pen.Color       = Color.Brown;
            pen.DashStyle   = DashStyle.Custom;
            pen.DashPattern = new float[] { 3, 4, 5, 6, 7, 8 };//선,공백,선,공백...
            e.Graphics.DrawLine(pen, 210, 10, 450, 10);

            pen.Color = Color.BurlyWood;
            for (int i = 0; i < 10; i++)
            {
                pen.DashOffset = i;
                e.Graphics.DrawLine(pen, 210, 50 + i * 20, 450, 50 + i * 20);
            }
#elif DASHANIMATION
            Pen pen = new Pen(Color.Goldenrod, 2);
            pen.DashStyle  = DashStyle.Dash;
            pen.DashOffset = Offset;
            e.Graphics.DrawRectangle(pen, 50, 10, 200, 150);
#elif PENCAP
            Pen pen = new Pen(Color.PaleGoldenrod, 9);
            pen.StartCap = pen.EndCap = LineCap.Flat;
            e.Graphics.DrawLine(pen, 10, 20, 200, 20);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 20);

            pen.StartCap = pen.EndCap = LineCap.Round;
            e.Graphics.DrawLine(pen, 10, 40, 200, 40);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 40);

            pen.StartCap = pen.EndCap = LineCap.Square;
            e.Graphics.DrawLine(pen, 10, 60, 200, 60);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 60);

            pen.StartCap = pen.EndCap = LineCap.Triangle;
            e.Graphics.DrawLine(pen, 10, 80, 200, 80);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 80);

            pen.StartCap = pen.EndCap = LineCap.RoundAnchor;
            e.Graphics.DrawLine(pen, 10, 100, 200, 100);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 100);

            pen.StartCap = pen.EndCap = LineCap.SquareAnchor;
            e.Graphics.DrawLine(pen, 10, 120, 200, 120);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 120);

            pen.StartCap = pen.EndCap = LineCap.ArrowAnchor;
            e.Graphics.DrawLine(pen, 10, 140, 200, 140);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 140);

            pen.StartCap = pen.EndCap = LineCap.DiamondAnchor;
            e.Graphics.DrawLine(pen, 10, 160, 200, 160);
            e.Graphics.DrawString(pen.StartCap.ToString(), Font, Brushes.Black, 210, 160);

            pen.StartCap  = pen.EndCap = LineCap.Flat;
            pen.Width     = 15;
            pen.DashStyle = DashStyle.Dash;
            pen.DashCap   = DashCap.Flat;
            e.Graphics.DrawLine(pen, 10, 200, 200, 200);
            e.Graphics.DrawString("DashCap:" + pen.DashCap.ToString(), Font, Brushes.Black, 210, 200);

            pen.DashCap = DashCap.Round;
            e.Graphics.DrawLine(pen, 10, 220, 200, 220);
            e.Graphics.DrawString("DashCap:" + pen.DashCap.ToString(), Font, Brushes.Black, 210, 220);

            pen.DashCap = DashCap.Triangle;
            e.Graphics.DrawLine(pen, 10, 240, 200, 240);
            e.Graphics.DrawString("DashCap:" + pen.DashCap.ToString(), Font, Brushes.Black, 210, 240);
#elif LINEJOIN
            Pen pen = new Pen(Color.Black, 15);
            pen.LineJoin = LineJoin.Miter;
            e.Graphics.DrawRectangle(pen, 10, 10, 80, 80);
            e.Graphics.DrawString(pen.LineJoin.ToString(), Font, Brushes.Gold, 10, 100);

            pen.LineJoin = LineJoin.MiterClipped;
            e.Graphics.DrawRectangle(pen, 120, 10, 80, 80);
            e.Graphics.DrawString(pen.LineJoin.ToString(), Font, Brushes.Gold, 130, 100);

            pen.LineJoin = LineJoin.Bevel;
            e.Graphics.DrawRectangle(pen, 10, 120, 80, 80);
            e.Graphics.DrawString(pen.LineJoin.ToString(), Font, Brushes.Gold, 10, 220);

            pen.LineJoin = LineJoin.Round;
            e.Graphics.DrawRectangle(pen, 120, 120, 80, 80);
            e.Graphics.DrawString(pen.LineJoin.ToString(), Font, Brushes.Gold, 130, 220);
#elif PENALIGN
            // PenAlignment : 폐곡선을 그릴때만 적용됨
            // Center와 Inset 만 구현되어 있고 나머지는 구현되어 있지 않아 Center(Default) 와 동일하다.

            Pen pen = new Pen(Color.DodgerBlue, 15);
            pen.Alignment = PenAlignment.Center;
            e.Graphics.DrawRectangle(pen, 10, 10, 80, 80);
            e.Graphics.DrawRectangle(Pens.Black, 10, 10, 80, 80);

            pen.Alignment = PenAlignment.Inset;
            e.Graphics.DrawRectangle(pen, 120, 10, 80, 80);
            e.Graphics.DrawRectangle(Pens.Black, 120, 10, 80, 80);

            pen.Alignment = PenAlignment.Outset;
            e.Graphics.DrawRectangle(pen, 10, 120, 80, 80);
            e.Graphics.DrawRectangle(Pens.Black, 10, 120, 80, 80);

            pen.Alignment = PenAlignment.Left;
            e.Graphics.DrawRectangle(pen, 120, 120, 80, 80);
            e.Graphics.DrawRectangle(Pens.Black, 120, 120, 80, 80);
#elif HATCHBRUSH
            // HatchBrush: 무늬가 있는 브러쉬. 속성들은 읽기전용이므로 변경하려면 새 브러쉬를 생성해야 함.

            int        x, y;
            HatchStyle style = (HatchStyle)0;
            for (y = 0; ; y++)
            {
                for (x = 0; x < 8; x++)
                {
                    HatchBrush brush = new HatchBrush(style, Color.White, Color.Black);
                    e.Graphics.FillRectangle(brush, x * 70, y * 70, 60, 60);
                    style++;
                    if (style > (HatchStyle)52)
                    {
                        break;
                    }
                }
                if (style > (HatchStyle)52)
                {
                    break;
                }
            }
#elif LINEARGRADIENT
            LinearGradientBrush brushPoint = new LinearGradientBrush(new Point(0, 0), new Point(100, 100), Color.Blue, Color.Yellow);
            e.Graphics.FillRectangle(brushPoint, 0, 0, 300, 150);

            LinearGradientBrush brushRect = new LinearGradientBrush(new Rectangle(0, 0, 100, 100), Color.White, Color.Black, Angle);
            e.Graphics.FillRectangle(brushRect, 0, 200, 300, 150);
            e.Graphics.DrawString("Angle: " + Angle, Font, Brushes.Gainsboro, 0, 370);
#elif TEXTUREBRUSH
            bool         isOrigin = true;
            TextureBrush brush    = new TextureBrush(ImgSrc);// new TextureBrush(img, WrapMode.TileFlipX);
            if (isOrigin)
            {
                // 원점(0, 0)에 출력
                e.Graphics.FillRectangle(brush, ClientRectangle);
            }
            else
            {
                // 이동 지점(50, 50)에 출력 :
                //      FillRectangle 에서 시작점을 50, 50으로 이동하므로
                //      텍스처브러시의 시작점도 Matrix 메서드를 이용해 50, 50 이동해 시작 원점 재정렬 필요(최좌측/최상측 이미지 이동위치만큼 잘림현상 해결).
                brush.Transform = new Matrix(1, 0, 0, 1, 50, 50);
                e.Graphics.FillRectangle(brush, 50, 50, ClientRectangle.Right, ClientRectangle.Bottom);
            }
#elif DRAWXXX
            if (DrawType == "Normal")
            {
                Point[] pointData = { new Point(112, 0), new Point(0, 83), new Point(45, 215), new Point(185, 215), new Point(223, 83), new Point(112, 0) };
                e.Graphics.DrawLines(Pens.Black, pointData);
            }
            else if (DrawType == "Polygon")
            {
                // XXXPolygon : 시작점과 끝점을 강제로 연결하여 폐곡선을 그린다.
                Point[] koreaData = { new Point(292,            6), new Point(331,           45), new Point(307,           45), new Point(269,              77)
                                      ,              new Point(274,          111), new Point(251,          116), new Point(207,          149), new Point(165, 155)
                                      ,              new Point(161,          190), new Point(201,          206), new Point(239,          270), new Point(258, 280)
                                      ,              new Point(257,          306), new Point(249,          313), new Point(251,          335), new Point(263, 333)
                                      ,              new Point(252,          364), new Point(231,          380), new Point(203,          378), new Point(201, 392)
                                      ,              new Point(181,          391), new Point(157,          389), new Point(143,          404), new Point(117, 402)
                                      ,              new Point(108,          416), new Point(95,           403), new Point(108,          393), new Point(96, 378)
                                      ,              new Point(121,          341), new Point(109,          302), new Point(96,           303), new Point(95, 292)
                                      ,              new Point(114,          285), new Point(132,          292), new Point(121,          267), new Point(114, 243)
                                      ,              new Point(74,           231), new Point(72,           251), new Point(26,           231), new Point(70, 205)
                                      ,              new Point(51,           198), new Point(71,           166), new Point(13,           142), new Point(90, 103)
                                      ,              new Point(132,           73), new Point(151,           56), new Point(161,           71), new Point(202, 79)
                                      ,              new Point(211,           66), new Point(206,           51), new Point(241,           49), new Point(266, 30)
                                      ,              new Point(282,           26), new Point(283, 7) };
                e.Graphics.FillPolygon(Brushes.LightGreen, koreaData);
                e.Graphics.DrawPolygon(new Pen(Color.Blue, 3), koreaData);
            }
            else if (DrawType == "Bezier")
            {
                e.Graphics.DrawBezier(Pens.Black, new Point(10, 10), new Point(150, 30), new Point(30, 150), new Point(200, 200));
            }
            else if (DrawType == "Curve")
            {
                Point[] curveData = { new Point(10, 80), new Point(100, 10), new Point(80, 200), new Point(200, 150) };
                e.Graphics.DrawCurve(Pens.Black, curveData, Tension);
                e.Graphics.DrawString("장력: " + Tension, Font, Brushes.Black, 0, 220);
            }
#elif COLOR_DIALOG
            Graphics   g     = e.Graphics;
            SolidBrush brush = new SolidBrush(this.ForeColor);
            Font       font  = new Font("돋움", 20);
            g.DrawString("글자색 변경", font, brush, 10, 20);
#elif GET_GRAPHICS
            Graphics g = e.Graphics;
            g.FillRectangle(new SolidBrush(Color.Blue), this.ClientRectangle);
#elif GET_GRAPHICS_byFROMIMAGE
            Graphics g = e.Graphics;
            if (m_img != null)
            {
                g.DrawImage(m_img, 0, 0);
            }
#elif GET_GRAPHICS_byMEASUREITEM
#elif GET_GRAPHICS_byDRAWITEM
#elif GET_GRAPHICS_byPrintPageEventArgs
#elif GET_GRAPHICS_byFromHwnd
#elif GET_GRAPHICS_byFromHdc
#elif DRAW_Figure
            Graphics g   = e.Graphics;
            Pen      pen = new Pen(Color.Black, 2);
            g.DrawLine(pen, 10, 10, 190, 190);
            g.DrawRectangle(pen, 10, 10, 100, 100);
            g.DrawEllipse(pen, 50, 50, 100, 100);
            g.DrawArc(pen, 100, 100, 80, 80, 0, -90);
#elif DRAW_Polygon
            Graphics g   = e.Graphics;
            Pen      pen = new Pen(Color.Indigo, 2);
            g.DrawPolygon(pen, ptFive);

            pen.Color = Color.MediumAquamarine;
            g.DrawPolygon(pen, ptThree);

            pen.Color = Color.Khaki;
            pen.Width = 1;

            for (int i = 0; i < 200; i += 20)
            {
                g.DrawEllipse(pen, 70, 130, i, i + 50);
            }
#elif FILLXXX
            Font     font = new Font("맑은 고딕", 10);
            Pen      pen  = new Pen(Brushes.DarkGreen, 1);
            Graphics g    = e.Graphics;
            g.FillEllipse(Brushes.RosyBrown, 10, 100, 50, 50);
            g.DrawString("위치: 10, 100, 크기: 50, 50, 원", font, Brushes.DarkGray, new Point(60, 120));
            g.DrawLine(pen, 35, 125, 60, 130);

            GraphicsPath gPath = new GraphicsPath();
            gPath.AddEllipse(0, 0, 150, 100);
            g.FillPath(Brushes.IndianRed, gPath);
            //g.DrawString("위치: 0, 0, 크기: 150, 100, 타원", font, Brushes.DarkGray, new Point(150, 45));
            g.DrawString("위치: 0, 0, 크기: 150, 100, 타원", font, Brushes.DarkGray, new Point(150, 0));
            g.DrawLine(pen, 75, 50, 150, 10);

            g.FillPie(Brushes.YellowGreen, 200, 10, 100, 100, 90, 180);
            g.DrawString("위치: 200, 10, 크기: 100, 100, 파이", font, Brushes.DarkGray, new Point(300, 50));
            g.DrawLine(pen, 225, 60, 300, 60);

            g.FillPolygon(Brushes.Green, ptThree);
            //g.DrawString("위치: 100, 10, 크기: 100, 100, 삼각", font, Brushes.DarkGray, new Point(200, 50));
            g.DrawString("위치: 100, 10, 크기: 100, 100, 삼각", font, Brushes.DarkGray, new Point(270, 120));
            g.DrawLine(pen, 150, 60, 270, 130);

            g.FillRectangle(Brushes.Maroon, 50, 150, 100, 100);
            g.DrawString("위치: 50, 150, 크기: 100, 100, 사각", font, Brushes.DarkGray, new Point(150, 300));
            g.DrawLine(pen, 100, 200, 150, 310);

            Rectangle rect   = new Rectangle(150, 150, 100, 100);
            Region    region = new Region(rect);
            g.FillRegion(Brushes.OrangeRed, region);
            g.DrawString("위치: 150, 150, 크기: 100, 100, 사각", font, Brushes.DarkGray, new Point(250, 350));
            g.DrawLine(pen, 200, 200, 250, 360);
#elif EXAM_GRADATION
            Graphics g = e.Graphics;
            for (int i = 0; i < 256; i++)
            {
                g.DrawLine(new Pen(Color.FromArgb(i, 0, 0)), 10, 10, 256 - i, 10 + i);
            }
#elif EXAM_TrafficLight
#else
            e.Graphics.FillEllipse(Brushes.Blue, 10, 10, 150, 100);
            SolidBrush brush = new SolidBrush(Color.FromArgb(Alpha, 255, 0, 0));
            e.Graphics.FillRectangle(brush, 50, 50, 150, 100);
            e.Graphics.DrawString("방향키↑: 투명도 증가, 방향키↓: 투명도 감소", Font, Brushes.Black, 10, 160);
#endif
        }
Beispiel #13
0
 public void AddEllipse(Rectangle rect)
 {
     Changed();
     gdiPath.AddEllipse(rect);
 }
Beispiel #14
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            gp.Reset();

            if (e.Button == MouseButtons.Left && Instrument_box.Text == "Brush")
            {
                curPnt = e.Location;
                g.FillEllipse(new SolidBrush(color), prPnt.X - width / 2, prPnt.Y - width / 2, width + 2, width + 2);
                prPnt = curPnt;
            }

            if (e.Button == MouseButtons.Left && Instrument_box.Text == "Pen")
            {
                curPnt = e.Location;
                g.DrawLine(new Pen(color, width), prPnt, curPnt);
                prPnt = curPnt;
            }

            if (Instrument_box.Text == "Line" && endLine == false)
            {
                curPnt = e.Location;
                gp.AddLine(prPnt, curPnt);
            }

            if ((Instrument_box.Text == "Rectangle" || Instrument_box.Text == "Ellipse") && endLine == false)
            {
                curPnt = e.Location;

                if (curPnt.X >= prPnt.X && curPnt.Y >= prPnt.Y)
                {
                    curPnt = e.Location;
                    prPnt  = X;
                }

                if (curPnt.X >= X.X && curPnt.Y <= X.Y)
                {
                    prPnt.Y  = e.Location.Y;
                    prPnt.X  = X.X;
                    curPnt.Y = X.Y;
                    curPnt.X = e.Location.X;
                }

                if (curPnt.X <= X.X && curPnt.Y >= X.Y)
                {
                    prPnt.X  = e.Location.X;
                    prPnt.Y  = X.Y;
                    curPnt.X = X.X;
                    curPnt.Y = e.Location.Y;
                }

                if (curPnt.X <= X.X && curPnt.Y <= X.Y)
                {
                    curPnt = X;
                    prPnt  = e.Location;
                }

                if (Instrument_box.Text == "Rectangle")
                {
                    gp.AddRectangle(new Rectangle(prPnt.X, prPnt.Y, curPnt.X - prPnt.X, curPnt.Y - prPnt.Y));
                }
                if (Instrument_box.Text == "Ellipse")
                {
                    gp.AddEllipse(new Rectangle(prPnt.X, prPnt.Y, curPnt.X - prPnt.X, curPnt.Y - prPnt.Y));
                }
            }



            pictureBox1.Refresh();
        }
Beispiel #15
0
 /// <summary>
 /// Draws the glow for the button when the
 /// mouse is inside the client area using
 /// the GlowColor property.
 /// </summary>
 /// <param name="g">The graphics object used in the paint event.</param>
 private void DrawGlow(Graphics g)
 {
     if (this.mButtonState == State.Pressed) { return; }
     SetClip(g);
     using (GraphicsPath glow = new GraphicsPath())
         {
         glow.AddEllipse(-5, this.Height / 2 - 10, this.Width + 11, this.Height + 11);
         using (PathGradientBrush gl = new PathGradientBrush(glow))
             {
             gl.CenterColor = Color.FromArgb(mGlowAlpha, this.GlowColor);
             gl.SurroundColors = new Color[] { Color.FromArgb(0, this.GlowColor) };
             g.FillPath(gl, glow);
             }
         }
     g.ResetClip();
 }
Beispiel #16
0
	public static void Main () 
	{

		Bitmap bmp = new Bitmap (600, 300);
		Graphics dc = Graphics.FromImage (bmp);        		
		Font fnt = new Font ("Arial", 8);
		Font fnttitle = new Font ("Arial", 8, FontStyle.Underline);
		Matrix matrix = new Matrix ();		
		GraphicsPath patha = new GraphicsPath ();
		GraphicsPath pathb = new GraphicsPath ();
		Pen redPen = new Pen (Color.Red, 2);		
		Region rgn1;
		Region rgn2;		
		int x = 0;		
		
		SolidBrush whiteBrush = new SolidBrush (Color.White);				
		
		dc.DrawString ("Region samples using GraphicsPath", fnttitle, whiteBrush, 5, 5);				
		
		/* First*/		
		patha.AddLine (60, 40, 90, 90);
		patha.AddLine (90, 90, 10, 90);
		patha.AddLine (10, 90, 60, 40);			
		dc.DrawPath (redPen, patha);		
				
		pathb.AddEllipse(30, 55, 60, 60);
		dc.DrawPath(redPen, pathb);
				
		rgn1 = new Region (patha);
		rgn2 = new Region (pathb);				
		rgn1.Complement (rgn2);
		dc.FillRegion (Brushes.Blue, rgn1);			
		dc.DrawString ("Complement (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 10, 140);	
		dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
		x += 110;
		
		/* Second*/		
		patha.Reset ();
		pathb.Reset ();
		patha.AddLine (60+x, 40, 90+x, 90);
		patha.AddLine (90+x, 90, 10+x, 90);
		patha.AddLine (10+x, 90, 60+x, 40);					
		
		dc.DrawPath (redPen, patha);						
				
		pathb.AddEllipse (30+x, 55, 60, 60);						
		dc.DrawPath(redPen, pathb);
				
		rgn1 = new Region (patha);
		rgn2 = new Region (pathb);				
		rgn1.Exclude (rgn2);
		dc.FillRegion (Brushes.Blue, rgn1);				
		dc.DrawString ("Exclude ("  + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 140, 140);	
		dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
		x += 110;
		
		/* Third*/		
		patha.Reset ();
		pathb.Reset ();
		patha.AddLine (60+x, 40, 90+x, 90);
		patha.AddLine (90+x, 90, 10+x, 90);
		patha.AddLine (10+x, 90, 60+x, 40);			
		
		dc.DrawPath (redPen, patha);		
				
		pathb.AddEllipse (30+x, 55, 60, 60);
		dc.DrawPath (redPen, pathb);
				
		rgn1 = new Region (patha);
		rgn2 = new Region (pathb);				
		rgn1.Intersect (rgn2);
		dc.FillRegion (Brushes.Blue, rgn1);		
		dc.DrawString ("Intersect ("  + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 270, 140);		
		dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));	
		x += 110;
		
		/* Four*/		
		patha.Reset ();
		pathb.Reset ();
		patha.AddLine (60+x, 40, 90+x, 90);
		patha.AddLine (90+x, 90, 10+x, 90);
		patha.AddLine (10+x, 90, 60+x, 40);			
		
		dc.DrawPath (redPen, patha);		
				
		pathb.AddEllipse (30+x, 55, 60, 60);
		dc.DrawPath (redPen, pathb);
				
		rgn1 = new Region (patha);
		rgn2 = new Region (pathb);				
		rgn1.Xor (rgn2);
		dc.FillRegion(Brushes.Blue, rgn1);		
		dc.DrawString ("Xor ("  + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 380, 140);		
		dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));	
		x += 110;	
		
		/* Fifth */		
		patha.Reset ();
		pathb.Reset ();
		patha.AddLine (60+x, 40, 90+x, 90);
		patha.AddLine (90+x, 90, 10+x, 90);
		patha.AddLine (10+x, 90, 60+x, 40);			
		
		dc.DrawPath (redPen, patha);		
				
		pathb.AddEllipse (30+x, 55, 60, 60);
		dc.DrawPath (redPen, pathb);
				
		rgn1 = new Region (patha);
		rgn2 = new Region (pathb);				
		rgn1.Union (rgn2);
		dc.FillRegion(Brushes.Blue, rgn1);		
		dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
		dc.DrawString ("Union (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 490, 140);							
		
        	bmp.Save("regionsgp.bmp", ImageFormat.Bmp);				
	}	
Beispiel #17
0
 /// <summary>
 /// Create region the same shape as the button. This will respond to the mouse click
 /// </summary>
 protected virtual void SetClickableRegion()
 {
     gpath = new GraphicsPath();
     gpath.AddEllipse(this.ClientRectangle);
     this.Region = new Region(gpath);                                    // Click only activates on elipse
 }
Beispiel #18
0
        /// <summary>
        /// 绘制水晶原形按钮
        /// </summary>
        /// <param name="g">The Graphics.</param>
        /// <param name="rect">The Rectangle.</param>
        /// <param name="surroundColor">Color of the surround.</param>
        /// <param name="centerColor">Color of the center.</param>
        /// <param name="lightColor">Color of the light.</param>
        /// <param name="blend">The blend.</param>
        /// User:K.Anding  CreateTime:2011-8-20 19:42.
        public static void DrawCrystalButton(Graphics g, Rectangle rect, Color surroundColor, Color centerColor, Color lightColor, Blend blend)
        {
            int       sweep, start;
            Point     p1, p2, p3;
            Rectangle rinner = rect;

            rinner.Inflate(-1, -1);
            using (GraphicsPath p = new GraphicsPath())
            {
                p.AddEllipse(rect);

                using (PathGradientBrush gradient = new PathGradientBrush(p))
                {
                    gradient.WrapMode       = WrapMode.Clamp;
                    gradient.CenterPoint    = new PointF(Convert.ToSingle(rect.Left + rect.Width / 2), Convert.ToSingle(rect.Bottom));
                    gradient.CenterColor    = centerColor;
                    gradient.SurroundColors = new Color[] { surroundColor };
                    gradient.Blend          = blend;
                    g.FillPath(gradient, p);
                }
            }

            // Bottom round shine
            Rectangle bshine = new Rectangle(0, 0, rect.Width / 2, rect.Height / 2);

            bshine.X = rect.X + (rect.Width - bshine.Width) / 2;
            bshine.Y = rect.Y + rect.Height / 2;

            using (GraphicsPath p = new GraphicsPath())
            {
                p.AddEllipse(bshine);

                using (PathGradientBrush gradient = new PathGradientBrush(p))
                {
                    gradient.WrapMode       = WrapMode.Clamp;
                    gradient.CenterPoint    = new PointF(Convert.ToSingle(rect.Left + rect.Width / 2), Convert.ToSingle(rect.Bottom));
                    gradient.CenterColor    = Color.White;
                    gradient.SurroundColors = new Color[] { Color.Transparent };

                    g.FillPath(gradient, p);
                }
            }

            // Upper Glossy
            using (GraphicsPath p = new GraphicsPath())
            {
                sweep = 160;
                start = 180 + (180 - sweep) / 2;
                p.AddArc(rinner, start, sweep);

                p1 = Point.Round(p.PathData.Points[0]);
                p2 = Point.Round(p.PathData.Points[p.PathData.Points.Length - 1]);
                p3 = new Point(rinner.Left + rinner.Width / 2, p2.Y - 3);
                p.AddCurve(new Point[] { p2, p3, p1 });

                using (PathGradientBrush gradient = new PathGradientBrush(p))
                {
                    gradient.WrapMode       = WrapMode.Clamp;
                    gradient.CenterPoint    = p3;
                    gradient.CenterColor    = Color.Transparent;
                    gradient.SurroundColors = new Color[] { lightColor };

                    blend           = new Blend(3);
                    blend.Factors   = new float[] { .3f, .8f, 1f };
                    blend.Positions = new float[] { 0, 0.50f, 1f };
                    gradient.Blend  = blend;

                    g.FillPath(gradient, p);
                }

                using (LinearGradientBrush b = new LinearGradientBrush(new Point(rect.Left, rect.Top), new Point(rect.Left, p1.Y), Color.White, Color.Transparent))
                {
                    blend           = new Blend(4);
                    blend.Factors   = new float[] { 0f, .4f, .8f, 1f };
                    blend.Positions = new float[] { 0f, .3f, .4f, 1f };
                    b.Blend         = blend;
                    g.FillPath(b, p);
                }
            }

            // Upper shine
            using (GraphicsPath p = new GraphicsPath())
            {
                sweep = 160;
                start = 180 + (180 - sweep) / 2;
                p.AddArc(rinner, start, sweep);

                using (Pen pen = new Pen(Color.White))
                {
                    g.DrawPath(pen, p);
                }
            }

            // Lower Shine
            using (GraphicsPath p = new GraphicsPath())
            {
                sweep = 160;
                start = (180 - sweep) / 2;
                p.AddArc(rinner, start, sweep);
                Point pt = Point.Round(p.PathData.Points[0]);

                Rectangle rrinner = rinner; rrinner.Inflate(-1, -1);
                sweep = 160;
                start = (180 - sweep) / 2;
                p.AddArc(rrinner, start, sweep);

                using (LinearGradientBrush b = new LinearGradientBrush(
                           new Point(rinner.Left, rinner.Bottom),
                           new Point(rinner.Left, pt.Y - 1),
                           lightColor, Color.FromArgb(50, lightColor)))
                {
                    g.FillPath(b, p);
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// Draws analog clock on the given GDI+ Drawing surface.
        /// </summary>
        /// <param name="e">The GDI+ Drawing surface.</param>
        private void DrawClock(Graphics e)
        {
            Graphics grfx = e;

            grfx.SmoothingMode     = smoothingMode;
            grfx.TextRenderingHint = textRenderingHint;
            grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            midx = this.ClientSize.Width / 2;
            midy = this.ClientSize.Height / 2;


            x = this.ClientSize.Width;
            y = this.ClientSize.Height;

            SolidBrush stringBrush = new SolidBrush(this.numeralColor);
            Pen        pen         = new Pen(stringBrush, 2);


            //Define rectangles inside which we will draw circles.

            Rectangle rect    = new Rectangle(0 + 10, 0 + 10, (int)x - 20, (int)y - 20);
            Rectangle rectrim = new Rectangle(0 + 20, 0 + 20, (int)x - 40, (int)y - 40);

            Rectangle rectinner      = new Rectangle(0 + 40, 0 + 40, (int)x - 80, (int)y - 80);
            Rectangle rectdropshadow = new Rectangle(0 + 10, 0 + 10, (int)x - 17, (int)y - 17);


            radius = rectinner.Width / 2;

            fontsize = radius / 5;
            textFont = this.Font;


            //Drop Shadow
            gb = new LinearGradientBrush(rect, Color.Transparent, dropShadowColor, LinearGradientMode.BackwardDiagonal);
            rectdropshadow.Offset(dropShadowOffset);
            if (this.drawDropShadow)
            {
                grfx.FillEllipse(gb, rectdropshadow);
            }


            //Face
            gb = new LinearGradientBrush(rect, rimColor1, rimColor2, faceGradientMode);
            if (this.drawRim)
            {
                grfx.FillEllipse(gb, rect);
            }



            //Rim
            gb = new LinearGradientBrush(rect, faceColor1, faceColor2, rimGradientMode);
            grfx.FillEllipse(gb, rectrim);



            //Define a circular clip region and draw the image inside it.
            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(rectrim);
            grfx.SetClip(path);

            if (this.img != null)
            {
                grfx.DrawImage(this.img, rect);
            }
            path.Dispose();

            //Reset clip region
            grfx.ResetClip();

            //			Triangular region
            //			pen.Width =2;
            //			grfx.DrawRectangle(pen, rect);
            //			grfx.DrawRectangle(pen, rectinner);
            //			grfx.DrawRectangle(pen, rectrim);
            //			grfx.DrawRectangle(pen, rectdropshadow);
            //
            //			grfx.DrawRectangle(pen, rect);
            //			grfx.DrawEllipse(pen, rect);
            //			grfx.DrawEllipse(pen, rectinner);
            //			grfx.DrawEllipse(pen, rectrim);
            //			grfx.DrawEllipse(pen, rectdropshadow);
            //


            //Center Point
            //grfx.DrawEllipse(pen, midx, midy ,2 ,2);

            //Define the midpoint of the control as the centre
            grfx.TranslateTransform(midx, midy);



            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;


            //Draw Numerals on the Face
            int deg = 360 / 12;

            if (drawnumerals)
            {
                for (int i = 1; i <= 12; i++)
                {
                    grfx.DrawString(i.ToString(), textFont, stringBrush, -1 * GetX(i * deg + 90), -1 * GetY(i * deg + 90), format);
                }
            }
            format.Dispose();



            hour = time.Hour;
            min  = time.Minute;
            Point centre = new Point(0, 0);

            //Draw Minute hand
            if (drawMinuteHand)
            {
                if (minHandTickStyle == TickStyle.Smooth)
                {
                    minuteAngle = (float)(2.0 * Math.PI * (min + sec / 60.0) / 60.0);
                }
                else
                {
                    minuteAngle = (float)(2.0 * Math.PI * (min / 60.0));
                }

                pen.EndCap   = LineCap.Round;
                pen.StartCap = LineCap.RoundAnchor;
                pen.Width    = (int)radius / 14;

                centre.Offset(2, 2);
                pen.Color = Color.Gray;
                Point minHandShadow = new Point((int)(radius * Math.Sin(minuteAngle)), (int)(-(radius) * Math.Cos(minuteAngle) + 2));


                if (this.drawMinuteHandShadow)
                {
                    pen.Color = minuteHandDropShadowColor;
                    grfx.DrawLine(pen, centre, minHandShadow);
                }

                centre.X  = centre.Y = 0;
                pen.Color = minHandColor;
                Point minHand = new Point((int)(radius * Math.Sin(minuteAngle)), (int)(-(radius) * Math.Cos(minuteAngle)));
                grfx.DrawLine(pen, centre, minHand);
            }

            //--End Minute Hand


            // Draw Hour Hand
            if (drawHourHand)
            {
                hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;


                pen.EndCap   = LineCap.Round;
                pen.StartCap = LineCap.RoundAnchor;
                pen.Width    = (int)radius / 14;

                centre.X  = centre.Y = 1;
                pen.Color = Color.Gray;
                Point hourHandShadow = new Point((int)((radius * Math.Sin(hourAngle) / 1.5) + 2), (int)((-(radius) * Math.Cos(hourAngle) / 1.5) + 2));

                if (this.drawHourHandShadow)
                {
                    pen.Color = hourHandDropShadowColor;
                    grfx.DrawLine(pen, centre, hourHandShadow);
                }

                centre.X  = centre.Y = 0;
                pen.Color = hourHandColor;
                Point hourHand = new Point((int)(radius * Math.Sin(hourAngle) / 1.5), (int)(-(radius) * Math.Cos(hourAngle) / 1.5));
                grfx.DrawLine(pen, centre, hourHand);
            }
            //---End Hour Hand


            if (secondHandTickStyle == TickStyle.Smooth)
            {
                sec = time.Second + (time.Millisecond * 0.001);
            }
            else
            {
                sec = time.Second;
            }


            //Draw Sec Hand
            if (drawSecondHand)
            {
                int width = (int)radius / 25;
                pen.Width    = width;
                pen.EndCap   = secLineEndCap;
                pen.StartCap = LineCap.RoundAnchor;
                secondAngle  = 2.0 * Math.PI * sec / 60.0;



                //Draw Second Hand Drop Shadow
                pen.Color = Color.DimGray;
                centre.X  = 1;
                centre.Y  = 1;

                Point secHand       = new Point((int)(radius * Math.Sin(secondAngle)), (int)(-(radius) * Math.Cos(secondAngle)));
                Point secHandshadow = new Point((int)(radius * Math.Sin(secondAngle)), (int)(-(radius) * Math.Cos(secondAngle) + 2));



                if (drawSecondHandShadow)
                {
                    pen.Color = secondHandDropShadowColor;
                    grfx.DrawLine(pen, centre, secHandshadow);
                }

                centre.X  = centre.Y = 0;
                pen.Color = secondHandColor;
                grfx.DrawLine(pen, centre, secHand);
            }
            pen.Dispose();
        }
Beispiel #20
0
        public MemoryStream GetImage(string sessionId, string path, string nick, string message, Image avatar = null)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (!Directory.Exists(Path.Combine(path, "Handled")))
            {
                Directory.CreateDirectory(Path.Combine(path, "Handled"));
            }
            int      panel_left = 40;
            int      width, height = 70, font_size = 10;
            Bitmap   bmp = new Bitmap(100, height);
            Graphics g   = Graphics.FromImage(bmp);

            width = (int)g.MeasureString(message, new Font("微软雅黑", font_size)).Width;
            int   width_tmp    = (int)g.MeasureString(nick, new Font("微软雅黑", font_size - 1.2f)).Width + 10;
            float offset_width = (141 - width) * 0.055f;

            g.Dispose();
            bmp.Dispose();
            int true_width = (width > width_tmp ? width + 30 : width_tmp) + panel_left;

            bmp = new Bitmap(true_width < 100 ? 100 : true_width, height);
            g   = Graphics.FromImage(bmp);
            Debug.WriteLine(Environment.CurrentDirectory);
            Image     img_left  = Image.FromFile(Path.Combine(path, "left.png"));
            Image     img_right = Image.FromFile(Path.Combine(path, "right.png"));
            Image     cover     = Image.FromFile(Path.Combine(path, "cover.png"));
            Rectangle rec_panel = new Rectangle(panel_left, 0, height, width);

            g.Clear(Color.White);
            g.CompositingQuality = CompositingQuality.HighQuality;

            if (avatar != null)
            {
                g.DrawImage(avatar, 7, 7, 30, 30); // ava
                g.DrawImage(cover, 7, 7, 30, 30);  // ava
            }
            GraphicsPath gp = new GraphicsPath();

            gp.AddEllipse(new Rectangle(7, 7, 30, 30));

            g.DrawString(nick, new Font("微软雅黑", font_size - 1.2f), new SolidBrush(Color.FromArgb(128, 128, 128)),
                         new PointF(rec_panel.X + 5f, rec_panel.Y + 5f));                                       // nick

            g.DrawImage(img_left, rec_panel.X + 2f, rec_panel.Y + 25f);                                         // left
            g.FillRectangle(new SolidBrush(Color.FromArgb(229, 229, 229)), rec_panel.X + img_left.Width, rec_panel.Y + 25f,
                            width + 1 + offset_width + 1, img_left.Height);                                     // rectangle fill
            g.DrawImage(img_right, rec_panel.X + img_left.Width + width + 1 + offset_width, rec_panel.Y + 25f); // right

            g.DrawString(message, new Font("微软雅黑", font_size), Brushes.Black,
                         new PointF(rec_panel.X + 17f, rec_panel.Y + 36f)); // message

            MemoryStream ms = new MemoryStream();

            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            bmp.Save(Path.Combine(path, "Handled", sessionId + ".png"), System.Drawing.Imaging.ImageFormat.Png);
            g.Dispose();
            bmp.Dispose();
            return(ms);
        }
Beispiel #21
0
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        int intRate = 0;
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        Color UseFillColor = new Color();
        Color UseBorderColor = new Color();
        GraphicsPath ShapePath = new GraphicsPath();
        float ptx;
        float pty;
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;

        pty = (this.Height - (RadiusOuter * 2)) / 2;
        intRate = 0;
        while (!(intRate == MaxRating))
        {
          ptx = intRate * (RadiusOuter * 2 + ShapeGap) + Padding.Left + (ShapeGap / 2);
          if (PaintRating > intRate)
          {
        if (!IsPainting & HighlightRateFill & (PaintRating != intRate + 1))
        {
          UseFillColor = ShapeColorHover;
          UseBorderColor = ShapeBorderHoverColor;
        }
        else if (IsPainting & HighlightRateHover & (PaintRating == intRate + 1))
        {
          UseFillColor = ShapeColorFill;
          UseBorderColor = ShapeBorderFilledColor;
        }
        else
        {
          UseFillColor = PaintColor;
          UseBorderColor = PaintBorderColor;
        }
          }
          else
          {
        UseFillColor = ShapeColorEmpty;
        UseBorderColor = ShapeBorderEmptyColor;
          }

          ShapePath.Reset();
          Point[] pts;
          switch (Shape)
          {
        case eShape.Star:
          ShapePath = DrawStar(ptx, pty);
          break;
        case eShape.Heart:
          ShapePath = DrawHeart(ptx, pty);
          break;
        case eShape.Square:
          ShapePath.AddRectangle(new Rectangle((int)ptx, (int)pty, (int)(RadiusOuter * 2), (int)(RadiusOuter * 2)));
          break;
        case eShape.Circle:
          ShapePath.AddEllipse(ptx, pty, RadiusOuter * 2, RadiusOuter * 2);
          break;
        case eShape.Diamond:
          pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter)), new Point((int)(ptx + RadiusOuter), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter)) };
          ShapePath.AddPolygon(pts);
          break;
        case eShape.Triangle:
          pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter * 2)) };
          ShapePath.AddPolygon(pts);
          break;

          }

          e.Graphics.FillPath(new SolidBrush(UseFillColor), ShapePath);
          e.Graphics.DrawPath(new Pen(UseBorderColor, ShapeBorderWidth), ShapePath);

          if (ShapeNumberShow != eShapeNumberShow.None)
          {
        if (ShapeNumberShow == eShapeNumberShow.All | (ShapeNumberShow == eShapeNumberShow.RateOnly & PaintRating == intRate + 1))
        {
          e.Graphics.DrawString((intRate + 1).ToString(), ShapeNumberFont, new SolidBrush(ShapeNumberColor), new RectangleF(ShapeNumberIndent.X + ptx, ShapeNumberIndent.Y + pty, RadiusOuter * 2, RadiusOuter * 2), sf);
        }
          }

          intRate += 1;
        }

        if (LabelShow)
        {
          int R_x = (int)(((RadiusOuter * 2) * (MaxRating)) + LabelIndent + ((ShapeGap) * MaxRating) + Padding.Left);
          if (IsPainting)
          {
        RateLabel.Text = GetLabelText(LabelTypeHover);
          }
          else
          {
        RateLabel.Text = GetLabelText(LabelTypeText);
          }
          RateLabel.Width = (this.Width - R_x);
          RateLabel.Height = (this.Height);
          RateLabel.Location = new Point(R_x, 0);
        }
    }
Beispiel #22
0
        /// <summary>
        /// Create the corner graphic
        /// </summary>
        internal override void Create()
        {
            Rectangle arc = new Rectangle(_shadowWidth, _shadowWidth, 0, 0);
            Rectangle box = new Rectangle(0, 0, 0, 0);

            arc.Width  = (2 * _radius) - 1;
            arc.Height = arc.Width;

            // graphic box to extend the radius graphic
            if (_extendHeight > 0)
            {
                box.Width  = arc.Width;
                box.Height = _extendHeight;
            }
            else if (_extendWidth > 0)
            {
                box.Width  = _extendWidth;
                box.Height = arc.Height;
            }

            // coordinates are for upper left of a bounding rectangle for
            // a complete ellipse even if only 90° is visible
            switch (_position)
            {
            case Positions.TopLeft:
                if (_extendHeight > 0)
                {
                    box.X = arc.X;
                    box.Y = arc.Y + _radius;
                }
                else if (_extendWidth > 0)
                {
                    box.X = arc.X + _radius;
                    box.Y = arc.Y;
                }
                break;

            case Positions.TopRight:
                arc.X = -_radius;

                if (_extendHeight > 0)
                {
                    box.Y = arc.Y + _radius;
                    box.X = arc.X;
                }
                else if (_extendWidth > 0)
                {
                    box.Y = _shadowWidth;
                }
                break;

            case Positions.BottomRight:
                arc.X = -_radius;
                arc.Y = -_radius;

                if (_extendHeight > 0)
                {
                    arc.Y += box.Height;
                }
                else if (_extendWidth > 0)
                {
                    arc.X += box.Width;
                }
                break;

            case Positions.BottomLeft:
                arc.Y = -_radius;

                if (_extendHeight > 0)
                {
                    box.X  = _shadowWidth;
                    arc.Y += box.Height;
                }
                else if (_extendWidth > 0)
                {
                    box.X = arc.X + arc.Width;
                }
                break;
            }

            if (_hasBorder)
            {
                int holdBack = (int)(this.BorderWidth / 3);
                arc.Y += (_position == Positions.BottomLeft ||
                          _position == Positions.BottomRight) ? -holdBack : holdBack;

                arc.X += (_position == Positions.TopRight ||
                          _position == Positions.BottomRight) ? -holdBack : holdBack;
            }

            // draw shadow
            if (_shadowWidth > 0)
            {
                GraphicsPath exclusions = new GraphicsPath();
                Rectangle    r          = new Rectangle();
                Rectangle    clone      = new Rectangle();

                clone.X      = arc.X;
                clone.Y      = arc.Y;
                clone.Width  = arc.Width;
                clone.Height = arc.Height;
                clone.Inflate(-1, -1);

                if (_extendHeight > 0)
                {
                    r.Y      = box.Y;
                    r.Width  = this.Width;
                    r.Height = box.Height;
                }
                else if (_extendWidth > 0)
                {
                    r.X      = box.X;
                    r.Width  = box.Width;
                    r.Height = this.Height;
                }
                exclusions.AddRectangle(r);
                exclusions.AddEllipse(clone);

                this.DrawShadow(arc, Shapes.Ellipse, exclusions);

                // box shadow
                if (_extendHeight > 0 || _extendWidth > 0)
                {
                    exclusions.Reset();
                    r.X = 0;
                    r.Y = 0;

                    if (_extendHeight > 0)
                    {
                        r.Height = this.Height - box.Height;
                        r.Y      = (_position == Positions.TopLeft ||
                                    _position == Positions.TopRight) ? 0 : box.Height;
                    }
                    else if (_extendWidth > 0)
                    {
                        r.Width = this.Width - box.Width;
                        r.X     = (_position == Positions.TopLeft ||
                                   _position == Positions.BottomLeft) ? 0 : box.Width;
                    }
                    exclusions.AddRectangle(r);

                    this.DrawShadow(box, Shapes.Rectangle, exclusions);
                }
            }
            // draw arc
            this.Graphic.FillEllipse(this.ForegroundBrush, arc);

            if (_hasBorder)
            {
                this.Graphic.DrawArc(this.BorderPen, arc, 0, 360);
            }
            // draw extension box
            if (_extendHeight > 0 || _extendWidth > 0)
            {
                this.Graphic.FillRectangle(this.ForegroundBrush, box);
            }
        }
    protected override void PaintHook()
    {
        G.Clear(BackColor);
        G.SmoothingMode = SmoothingMode.HighQuality;
        if (_Checked)
        {
            LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(14, 14)), G1, G2, 90f);
            G.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(14, 14)));
        }
        else
        {
            LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(14, 16)), G1, G2, 90f);
            G.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(14, 14)));
        }

        if (State == MouseState.Over & X < 15)
        {
            SolidBrush SB = new SolidBrush(Color.FromArgb(10, Color.Black));
            G.FillEllipse(SB, new Rectangle(new Point(0, 0), new Size(14, 14)));
        }
        else if (State == MouseState.Down & X < 15)
        {
            SolidBrush SB = new SolidBrush(Color.FromArgb(20, Color.Black));
            G.FillEllipse(SB, new Rectangle(new Point(0, 0), new Size(14, 14)));
        }

        GraphicsPath P = new GraphicsPath();
        P.AddEllipse(new Rectangle(0, 0, 14, 14));
        G.SetClip(P);

        LinearGradientBrush LLGGBB = new LinearGradientBrush(new Rectangle(0, 0, 14, 5), Color.FromArgb(150, Color.White), Color.Transparent, 90f);
        G.FillRectangle(LLGGBB, LLGGBB.Rectangle);

        G.ResetClip();

        G.DrawEllipse(new Pen(Bo), new Rectangle(new Point(0, 0), new Size(14, 14)));

        if (_Checked)
        {
            SolidBrush LGB = new SolidBrush(Bb);
            G.FillEllipse(LGB, new Rectangle(new Point(4, 4), new Size(6, 6)));
        }

        DrawText(new SolidBrush(TextColor), HorizontalAlignment.Left, 17, -2);
    }
Beispiel #24
0
        private GraphicsPath CalculateArrowPath
        (
            IGArrowCapStyle arrowCap,
            PointF arrowPoint,
            PointF otherPoint,
            float length,
            float width,
            float backPuffyLenght)
        {
            if (arrowCap == IGArrowCapStyle.None)
            {
                return(null);
            }

            float        tmpW;
            GraphicsPath arrowPath = new GraphicsPath();

            switch (arrowCap)
            {
            case IGArrowCapStyle.Arrow:
                double lineAngleRad = Math.Atan2(arrowPoint.Y - otherPoint.Y, arrowPoint.X - otherPoint.X);
                double pointY       = arrowPoint.Y - Math.Sin(lineAngleRad) * (length + backPuffyLenght);
                double pointX       = arrowPoint.X - Math.Cos(lineAngleRad) * (length + backPuffyLenght);

                PointF arrowpPointFront = arrowPoint;
                PointF arrowpPointBack  = new PointF((float)pointX, (float)pointY);

                double arrowCapAngleRad = Math.Atan2(width, length);
                double tmpRad           = Math.PI - arrowCapAngleRad + lineAngleRad;
                double capLength        = Math.Sqrt(Math.Pow(length, 2) + Math.Pow(width, 2));
                pointY = arrowPoint.Y + Math.Sin(tmpRad) * capLength;
                pointX = arrowPoint.X + Math.Cos(tmpRad) * capLength;
                PointF arrowpPointLeft = new PointF((float)pointX, (float)pointY);

                tmpRad = Math.PI + arrowCapAngleRad + lineAngleRad;
                pointY = arrowPoint.Y + Math.Sin(tmpRad) * capLength;
                pointX = arrowPoint.X + Math.Cos(tmpRad) * capLength;
                PointF arrowpPointRight = new PointF((float)pointX, (float)pointY);

                arrowPath.AddPolygon(new PointF[] { arrowpPointFront, arrowpPointLeft, arrowpPointBack, arrowpPointRight });

                break;

            case IGArrowCapStyle.Ellipse:
                arrowPath.AddEllipse(arrowPoint.X - (width / 2), arrowPoint.Y - (width / 2), width, width);
                break;

            case IGArrowCapStyle.Rectangle:
                arrowPath.AddRectangle(new RectangleF(arrowPoint.X - (width / 2), arrowPoint.Y - (width / 2), width, width));
                break;

            case IGArrowCapStyle.RoundedRectangle:
                tmpW = width / 1.5f;
                float radius = width / 2;
                arrowPath.AddArc(arrowPoint.X + tmpW - radius, arrowPoint.Y - tmpW, radius, radius, -90, 90);
                arrowPath.AddArc(arrowPoint.X + tmpW - radius, arrowPoint.Y + tmpW - radius, radius, radius, 0, 90);
                arrowPath.AddArc(arrowPoint.X - tmpW, arrowPoint.Y + tmpW - radius, radius, radius, 90, 90);
                arrowPath.AddArc(arrowPoint.X - tmpW, arrowPoint.Y - tmpW, radius, radius, 180, 90);
                break;

            case IGArrowCapStyle.Diamond:
                tmpW = width / 1.5f;
                arrowPath.AddPolygon(new PointF[]
                {
                    new PointF(arrowPoint.X, arrowPoint.Y - tmpW),
                    new PointF(arrowPoint.X + tmpW, arrowPoint.Y),
                    new PointF(arrowPoint.X, arrowPoint.Y + tmpW),
                    new PointF(arrowPoint.X - tmpW, arrowPoint.Y)
                });
                break;
            }

            arrowPath.CloseFigure();
            return(arrowPath);
        }
Beispiel #25
0
        /// <summary>
        /// Draw the "joystick" on the screen (a.k.a. Trackball)
        /// </summary>
        /// <param name="x">The x position of the joystick</param>
        /// <param name="y">The y position of the joystick</param>
        private void DrawJoystick(int x, int y)
        {
            Bitmap bmp = null;

            try
            {
                bmp = new Bitmap(this.JoystickPicture.Width, this.JoystickPicture.Height);

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        int width  = bmp.Width - 1;
                        int height = bmp.Height - 1;

                        g.Clear(Color.Transparent);
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        path.AddEllipse(0, 0, width, height);

                        using (PathGradientBrush pathBrush = new PathGradientBrush(path))
                        {
                            pathBrush.CenterPoint    = new PointF(width / 3f, height / 3f);
                            pathBrush.CenterColor    = Color.White;
                            pathBrush.SurroundColors = new Color[] { Color.LightGray };

                            g.FillPath(pathBrush, path);
                            g.DrawPath(Pens.Black, path);

                            int partial = y * height / 2200;
                            if (partial > 0)
                            {
                                g.DrawArc(
                                    Pens.Black,
                                    0,
                                    (height / 2) - partial,
                                    width,
                                    2 * partial,
                                    180,
                                    180);
                            }
                            else if (partial == 0)
                            {
                                g.DrawLine(Pens.Black, 0, height / 2, width, height / 2);
                            }
                            else
                            {
                                g.DrawArc(
                                    Pens.Black,
                                    0,
                                    (height / 2) + partial,
                                    width,
                                    -2 * partial,
                                    0,
                                    180);
                            }

                            partial = x * width / 2200;
                            if (partial > 0)
                            {
                                g.DrawArc(
                                    Pens.Black,
                                    (width / 2) - partial,
                                    0,
                                    2 * partial,
                                    height,
                                    270,
                                    180);
                            }
                            else if (partial == 0)
                            {
                                g.DrawLine(Pens.Black, width / 2, 0, width / 2, height);
                            }
                            else
                            {
                                g.DrawArc(
                                    Pens.Black,
                                    (width / 2) + partial,
                                    0,
                                    -2 * partial,
                                    height,
                                    90,
                                    180);
                            }

                            this.JoystickPicture.Image = bmp;
                            bmp = null;
                        }
                    }
                }
            }
            finally
            {
                if (bmp != null)
                {
                    bmp.Dispose();
                    bmp = null;
                }
            }
        }
        internal GraphicsPath GetFramePath(GaugeGraphics g, float shrinkBy)
        {
            RectangleF frameRectangle    = GetFrameRectangle(g);
            float      absoluteDimension = g.GetAbsoluteDimension(shrinkBy);

            frameRectangle.Inflate(0f - absoluteDimension, 0f - absoluteDimension);
            if (shrinkBy > 0f)
            {
                frameRectangle.Inflate(1f, 1f);
            }
            if (FrameShape == BackFrameShape.Circular)
            {
                GraphicsPath graphicsPath = new GraphicsPath();
                graphicsPath.AddEllipse(frameRectangle);
                return(graphicsPath);
            }
            if (FrameShape == BackFrameShape.AutoShape)
            {
                GraphicsPath graphicsPath2 = new GraphicsPath();
                if (Parent is CircularGauge)
                {
                    CircularGauge circularGauge = (CircularGauge)Parent;
                    if (circularGauge.Scales.Count == 0)
                    {
                        graphicsPath2.AddEllipse(frameRectangle);
                    }
                    else
                    {
                        BuildCircularGaugeAutoFrame(g, graphicsPath2, circularGauge, shrinkBy);
                    }
                }
                else
                {
                    graphicsPath2.AddRectangle(frameRectangle);
                }
                return(graphicsPath2);
            }
            if (FrameShape != BackFrameShape.RoundedRectangular)
            {
                if (FrameShape == BackFrameShape.Rectangular)
                {
                    GraphicsPath graphicsPath3 = new GraphicsPath();
                    graphicsPath3.AddRectangle(frameRectangle);
                    return(graphicsPath3);
                }
                GraphicsPath graphicsPath4 = new GraphicsPath();
                graphicsPath4.FillMode = FillMode.Winding;
                XamlRenderer cachedXamlRenderer = GetCachedXamlRenderer(g);
                graphicsPath4.AddPath(cachedXamlRenderer.Layers[0].Paths[0], connect: false);
                return(graphicsPath4);
            }
            float num  = (!(frameRectangle.Width > frameRectangle.Height)) ? frameRectangle.Width : frameRectangle.Height;
            float num2 = num / 8f;

            float[] array = new float[10];
            for (int i = 0; i < 10; i++)
            {
                array[i] = num2;
            }
            return(g.CreateRoundedRectPath(frameRectangle, array));
        }
Beispiel #27
0
        public ColourWheel(Rectangle colorRectangle, Rectangle brightnessRectangle, Rectangle selectedColorRectangle)
        {
            // Caller must provide locations for color wheel
            // (colorRectangle), brightness "strip" (brightnessRectangle)
            // and location to display selected color (selectedColorRectangle).

            using (GraphicsPath path = new GraphicsPath())
            {
                // Store away locations for later use.
                this.colorRectangle         = colorRectangle;
                this.brightnessRectangle    = brightnessRectangle;
                this.selectedColorRectangle = selectedColorRectangle;

                // Calculate the center of the circle.
                // Start with the location, then offset
                // the point by the radius.
                // Use the smaller of the width and height of
                // the colorRectangle value.
                this.radius      = (int)Math.Min(colorRectangle.Width, colorRectangle.Height) / 2;
                this.centerPoint = colorRectangle.Location;
                this.centerPoint.Offset(radius, radius);

                // Start the pointer in the center.
                this.colorPoint = this.centerPoint;

                // Create a region corresponding to the color circle.
                // Code uses this later to determine if a specified
                // point is within the region, using the IsVisible
                // method.
                path.AddEllipse(colorRectangle);
                colourRegion = new Region(path);

                // set { the range for the brightness selector.
                this.brightnessMin = this.brightnessRectangle.Top;
                this.brightnessMax = this.brightnessRectangle.Bottom;

                // Create a region corresponding to the
                // brightness rectangle, with a little extra
                // "breathing room".

                path.AddRectangle(new Rectangle(brightnessRectangle.Left, brightnessRectangle.Top - 10, brightnessRectangle.Width + 10, brightnessRectangle.Height + 20));
                // Create region corresponding to brightness
                // rectangle. Later code uses this to
                // determine if a specified point is within
                // the region, using the IsVisible method.
                brightnessRegion = new Region(path);

                // Set the location for the brightness indicator "marker".
                // Also calculate the scaling factor, scaling the height
                // to be between 0 and 255.
                brightnessX       = brightnessRectangle.Left + brightnessRectangle.Width;
                brightnessScaling = (double)255 / (brightnessMax - brightnessMin);

                // Calculate the location of the brightness
                // pointer. Assume it's at the highest position.
                brightnessPoint = new Point(brightnessX, brightnessMax);

                // Create the bitmap that contains the circular gradient.
                CreateGradient();
            }
        }
        private void BuildCircularGaugeAutoFrame(GaugeGraphics g, GraphicsPath path, CircularGauge gauge, float shrinkBy)
        {
            float startAngle = gauge.Scales[0].StartAngle;
            float num        = gauge.Scales[0].StartAngle + gauge.Scales[0].SweepAngle;
            float radius     = gauge.Scales[0].Radius;
            float num2       = gauge.Scales[0].GetLargestRadius(g);

            if (gauge.Scales.Count > 1)
            {
                for (int i = 1; i < gauge.Scales.Count; i++)
                {
                    if (startAngle > gauge.Scales[i].StartAngle)
                    {
                        startAngle = gauge.Scales[i].StartAngle;
                    }
                    if (num < gauge.Scales[i].StartAngle + gauge.Scales[i].SweepAngle)
                    {
                        num = gauge.Scales[i].StartAngle + gauge.Scales[i].SweepAngle;
                    }
                    if (radius < gauge.Scales[i].Radius)
                    {
                        radius = gauge.Scales[i].Radius;
                    }
                    float largestRadius = gauge.Scales[i].GetLargestRadius(g);
                    if (num2 < largestRadius)
                    {
                        num2 = largestRadius;
                    }
                }
            }
            float num3 = 0f;

            foreach (CircularPointer pointer in gauge.Pointers)
            {
                if (pointer.Visible && pointer.Type == CircularPointerType.Needle)
                {
                    float num4 = pointer.CapWidth / 2f * pointer.GetScale().Radius / 100f;
                    if (pointer.CapVisible && num4 > num3)
                    {
                        num3 = num4;
                    }
                    float num5 = pointer.GetNeedleTailLength() * pointer.GetScale().Radius / 100f;
                    if (num5 > num3)
                    {
                        num3 = num5;
                    }
                }
            }
            foreach (Knob knob in gauge.Knobs)
            {
                if (knob.Visible)
                {
                    float num6 = knob.Width * knob.GetScale().Radius / 100f;
                    if (num6 > num3)
                    {
                        num3 = num6;
                    }
                }
            }
            num3 = g.GetAbsoluteDimension(num3);
            float absoluteDimension  = g.GetAbsoluteDimension(radius / 5f);
            float absoluteDimension2 = g.GetAbsoluteDimension(FrameWidth * radius / 100f);
            float absoluteDimension3 = g.GetAbsoluteDimension(shrinkBy * radius / 100f);

            absoluteDimension += absoluteDimension2;
            absoluteDimension -= absoluteDimension3;
            float  num7               = num - startAngle;
            PointF absolutePoint      = g.GetAbsolutePoint(gauge.PivotPoint);
            float  absoluteDimension4 = g.GetAbsoluteDimension(num2);
            float  num8               = startAngle * (float)Math.PI / 180f;
            float  num9               = (360f - startAngle - num7) * (float)Math.PI / 180f;
            PointF pointF             = default(PointF);

            pointF.X = absolutePoint.X - absoluteDimension4 * (float)Math.Sin(num8);
            pointF.Y = absolutePoint.Y + absoluteDimension4 * (float)Math.Cos(num8);
            PointF pointF2 = default(PointF);

            pointF2.X = absolutePoint.X + absoluteDimension4 * (float)Math.Sin(num9);
            pointF2.Y = absolutePoint.Y + absoluteDimension4 * (float)Math.Cos(num9);
            RectangleF rect = new RectangleF(pointF.X, pointF.Y, 0f, 0f);

            rect.Inflate(absoluteDimension, absoluteDimension);
            RectangleF rect2 = new RectangleF(pointF2.X, pointF2.Y, 0f, 0f);

            rect2.Inflate(absoluteDimension, absoluteDimension);
            RectangleF rect3 = new RectangleF(absolutePoint.X, absolutePoint.Y, 0f, 0f);

            rect3.Inflate(absoluteDimension + num3, absoluteDimension + num3);
            RectangleF rect4 = new RectangleF(absolutePoint.X, absolutePoint.Y, 0f, 0f);

            rect4.Inflate(absoluteDimension4 + absoluteDimension, absoluteDimension4 + absoluteDimension);
            if (num7 < 270f)
            {
                path.AddArc(rect, startAngle + 270f + 90f, 90f);
                path.AddArc(rect4, startAngle + 90f, num7);
                path.AddArc(rect2, startAngle + num7 + 90f, 90f);
                path.AddArc(rect3, startAngle + num7 + 90f + 45f, 360f - num7 - 90f);
            }
            else if (num7 >= 320f)
            {
                path.AddEllipse(rect4);
            }
            else
            {
                float num10 = 90f - (360f - num7) / 2f;
                path.AddArc(rect, startAngle + 270f + 90f + num10, 90f - num10);
                path.AddArc(rect4, startAngle + 90f, num7);
                path.AddArc(rect2, startAngle + num7 + 90f, 90f - num10);
            }
            path.CloseFigure();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            B = new Bitmap(Width, Height);
            G = Graphics.FromImage(B);
            W = Width - 1;
            H = Height - 1;

            dynamic      GP     = default(GraphicsPath);
            GraphicsPath GP2    = new GraphicsPath();
            Rectangle    Base   = new Rectangle(0, 0, W, H);
            Rectangle    Toggle = new Rectangle(Convert.ToInt32(W / 2), 0, 38, H);

            var _with5 = G;

            _with5.SmoothingMode     = (SmoothingMode)2;
            _with5.PixelOffsetMode   = (PixelOffsetMode)2;
            _with5.TextRenderingHint = (TextRenderingHint)5;
            _with5.Clear(BackColor);

            switch (O)
            {
            case _Options.Style1:
                //-- Style 1
                //-- Base
                GP  = Helpers.RoundRec(Base, 6);
                GP2 = Helpers.RoundRec(Toggle, 6);
                _with5.FillPath(new SolidBrush(BGColor), GP);
                _with5.FillPath(new SolidBrush(ToggleColor), GP2);

                //-- Text
                _with5.DrawString("OFF", Font, new SolidBrush(BGColor), new Rectangle(19, 1, W, H), CenterSF);

                if (Checked)
                {
                    //-- Base
                    GP  = Helpers.RoundRec(Base, 6);
                    GP2 = Helpers.RoundRec(new Rectangle(Convert.ToInt32(W / 2), 0, 38, H), 6);
                    _with5.FillPath(new SolidBrush(ToggleColor), GP);
                    _with5.FillPath(new SolidBrush(BaseColor), GP2);

                    //-- Text
                    _with5.DrawString("ON", Font, new SolidBrush(BaseColor), new Rectangle(8, 7, W, H), NearSF);
                }
                break;

            case _Options.Style2:
                //-- Style 2
                //-- Base
                GP     = Helpers.RoundRec(Base, 6);
                Toggle = new Rectangle(4, 4, 36, H - 8);
                GP2    = Helpers.RoundRec(Toggle, 4);
                _with5.FillPath(new SolidBrush(BaseColorRed), GP);
                _with5.FillPath(new SolidBrush(ToggleColor), GP2);

                //-- Lines
                _with5.DrawLine(new Pen(BGColor), 18, 20, 18, 12);
                _with5.DrawLine(new Pen(BGColor), 22, 20, 22, 12);
                _with5.DrawLine(new Pen(BGColor), 26, 20, 26, 12);

                //-- Text
                _with5.DrawString("r", new Font("Marlett", 8), new SolidBrush(TextColor), new Rectangle(19, 2, Width, Height), CenterSF);

                if (Checked)
                {
                    GP     = Helpers.RoundRec(Base, 6);
                    Toggle = new Rectangle(Convert.ToInt32(W / 2) - 2, 4, 36, H - 8);
                    GP2    = Helpers.RoundRec(Toggle, 4);
                    _with5.FillPath(new SolidBrush(BaseColor), GP);
                    _with5.FillPath(new SolidBrush(ToggleColor), GP2);

                    //-- Lines
                    _with5.DrawLine(new Pen(BGColor), Convert.ToInt32(W / 2) + 12, 20, Convert.ToInt32(W / 2) + 12, 12);
                    _with5.DrawLine(new Pen(BGColor), Convert.ToInt32(W / 2) + 16, 20, Convert.ToInt32(W / 2) + 16, 12);
                    _with5.DrawLine(new Pen(BGColor), Convert.ToInt32(W / 2) + 20, 20, Convert.ToInt32(W / 2) + 20, 12);

                    //-- Text
                    _with5.DrawString("ü", new Font("Wingdings", 14), new SolidBrush(TextColor), new Rectangle(8, 7, Width, Height), NearSF);
                }
                break;

            case _Options.Style3:
                //-- Style 3
                //-- Base
                GP     = Helpers.RoundRec(Base, 16);
                Toggle = new Rectangle(W - 28, 4, 22, H - 8);
                GP2.AddEllipse(Toggle);
                _with5.FillPath(new SolidBrush(ToggleColor), GP);
                _with5.FillPath(new SolidBrush(BaseColorRed), GP2);

                //-- Text
                _with5.DrawString("OFF", Font, new SolidBrush(BaseColorRed), new Rectangle(-12, 2, W, H), CenterSF);

                if (Checked)
                {
                    //-- Base
                    GP     = Helpers.RoundRec(Base, 16);
                    Toggle = new Rectangle(6, 4, 22, H - 8);
                    GP2.Reset();
                    GP2.AddEllipse(Toggle);
                    _with5.FillPath(new SolidBrush(ToggleColor), GP);
                    _with5.FillPath(new SolidBrush(BaseColor), GP2);

                    //-- Text
                    _with5.DrawString("ON", Font, new SolidBrush(BaseColor), new Rectangle(12, 2, W, H), CenterSF);
                }
                break;

            case _Options.Style4:
                //-- TODO: New Styles
                if (Checked)
                {
                    //--
                }
                break;

            case _Options.Style5:
                //-- TODO: New Styles
                if (Checked)
                {
                    //--
                }
                break;
            }


            base.OnPaint(e);
            G.Dispose();
            e.Graphics.InterpolationMode = (InterpolationMode)7;
            e.Graphics.DrawImageUnscaled(B, 0, 0);
            B.Dispose();
        }
Beispiel #30
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     try
     {
         Rectangle rectangle = new Rectangle(base.ClientRectangle.Left + (f - 1), base.ClientRectangle.Top + (f - 1), base.ClientRectangle.Width - 1 - 2 * (f - 1), base.ClientRectangle.Height - 1 - 2 * (f - 1));
         if (rectangle.Width > j.X)
         {
             rectangle.X     += j.X;
             rectangle.Width -= j.X;
         }
         if (rectangle.Height > j.Y)
         {
             rectangle.Y      += j.Y;
             rectangle.Height -= j.Y;
         }
         if (rectangle.Width > k.X)
         {
             rectangle.Width -= k.X;
         }
         if (rectangle.Height > k.Y)
         {
             rectangle.Height -= k.Y;
         }
         e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
         e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
         if (!n)
         {
             SolidBrush solidBrush = new SolidBrush(base.Parent.BackColor);
             e.Graphics.FillRectangle(solidBrush, base.ClientRectangle);
             Pen pen = new Pen(solidBrush);
             e.Graphics.DrawRectangle(pen, base.ClientRectangle);
             pen.Dispose();
             solidBrush.Dispose();
         }
         int left = rectangle.Left;
         int top  = rectangle.Top;
         if (l != 0)
         {
             e.Graphics.TranslateTransform((rectangle.Left + rectangle.Right) / 2, (rectangle.Top + rectangle.Bottom) / 2);
             e.Graphics.RotateTransform(l);
             rectangle.X = -rectangle.Width / 2;
             rectangle.Y = -rectangle.Height / 2;
         }
         Pen pen2 = new Pen(g, f)
         {
             DashStyle = h
         };
         SolidBrush   solidBrush2  = new SolidBrush(ForeColor);
         SolidBrush   solidBrush3  = new SolidBrush(BackColor);
         GraphicsPath graphicsPath = new GraphicsPath();
         INBase       iNBase       = new INBase();
         if (c == HMIValveType.VT_Valve1 || c == HMIValveType.VT_Valve2 || c == HMIValveType.VT_Valve3)
         {
             Rectangle a_         = new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
             Rectangle rectangle2 = new Rectangle(rectangle.Left + (rectangle.Width - m) / 2, rectangle.Top, m, rectangle.Height);
             if (d != 0)
             {
                 a_.Y              = rectangle.Bottom - 6 * rectangle.Height / 10;
                 a_.Height         = 6 * rectangle.Height / 10;
                 rectangle2.Y      = rectangle.Top + rectangle.Height / 10 - 1;
                 rectangle2.Height = (a_.Top + a_.Bottom) / 2 - rectangle2.Y;
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, null, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 0, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillRectangle(solidBrush2, rectangle2);
                 }
                 e.Graphics.DrawRectangle(pen2, rectangle2);
                 rectangle2.X     = rectangle.Left + rectangle.Width / 2 - (int)(3.5 * (double)rectangle.Width / 10.0);
                 rectangle2.Width = 7 * rectangle.Width / 10;
                 rectangle2.Y     = rectangle.Top;
                 if (d == HMIValveKnobType.VKT_Rectangle)
                 {
                     rectangle2.Height = 2 * rectangle.Height / 10;
                 }
                 else
                 {
                     rectangle2.Height = 3 * rectangle.Height / 10;
                 }
                 if (d != HMIValveKnobType.VKT_Rectangle)
                 {
                     if (d != HMIValveKnobType.VKT_Ellipse)
                     {
                         graphicsPath.AddArc(rectangle2.Left, rectangle2.Top, rectangle2.Width, 2 * rectangle2.Height, 180f, 180f);
                         graphicsPath.AddLine(rectangle2.Right, rectangle2.Bottom, rectangle2.Left, rectangle2.Bottom);
                     }
                     else
                     {
                         graphicsPath.AddEllipse(rectangle2);
                     }
                 }
                 else
                 {
                     graphicsPath.AddRectangle(rectangle2);
                 }
                 if (!i)
                 {
                     SolidBrush solidBrush4 = new SolidBrush(this.e);
                     e.Graphics.FillPath(solidBrush4, graphicsPath);
                     solidBrush4.Dispose();
                 }
                 else if (d == HMIValveKnobType.VKT_Rectangle)
                 {
                     iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, this.e, Color.White, HMIBkGradientStyle.BKGS_Linear2, 0, 0.5f, 0, 0, 0f);
                 }
                 else if (d != HMIValveKnobType.VKT_Chord)
                 {
                     iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, this.e, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, this.e, Color.White, HMIBkGradientStyle.BKGS_Shine, 270, 0.5f, 0, 0, 0.8f);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
             }
             graphicsPath.Reset();
             if (c == HMIValveType.VT_Valve1)
             {
                 graphicsPath.AddLine((a_.Left + a_.Right) / 2, (a_.Top + a_.Bottom) / 2, a_.Left, a_.Top);
                 graphicsPath.AddLine(a_.Left, a_.Top, a_.Left, a_.Bottom);
                 graphicsPath.AddLine(a_.Left, a_.Bottom, (a_.Left + a_.Right) / 2, (a_.Top + a_.Bottom) / 2);
                 graphicsPath.AddLine((a_.Left + a_.Right) / 2, (a_.Top + a_.Bottom) / 2, a_.Right, a_.Top);
                 graphicsPath.AddLine(a_.Right, a_.Top, a_.Right, a_.Bottom);
                 graphicsPath.AddLine(a_.Right, a_.Bottom, (a_.Left + a_.Right) / 2, (a_.Top + a_.Bottom) / 2);
                 if (i)
                 {
                     iNBase.a(e.Graphics, a_, HMIShapeType.ST_Rectangle, graphicsPath, BackColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush3, graphicsPath);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
             }
             else
             {
                 rectangle2.X     = a_.Left + 1;
                 rectangle2.Width = a_.Width - 2;
                 if (c == HMIValveType.VT_Valve2)
                 {
                     rectangle2.Y      = (a_.Top + a_.Bottom) / 2 - a_.Height / 3;
                     rectangle2.Height = 2 * a_.Height / 3;
                     graphicsPath.AddRectangle(rectangle2);
                 }
                 else
                 {
                     rectangle2.Y      = a_.Y;
                     rectangle2.Height = a_.Height;
                     graphicsPath.AddEllipse(rectangle2);
                 }
                 if (i)
                 {
                     if (c != HMIValveType.VT_Valve2)
                     {
                         iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, BackColor, Color.White, HMIBkGradientStyle.BKGS_Shine, 90, 0.5f, 0, 0, 0f);
                     }
                     else
                     {
                         iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, BackColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
                     }
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush3, graphicsPath);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
                 rectangle2.X      = a_.Left;
                 rectangle2.Y      = a_.Top;
                 rectangle2.Width  = m;
                 rectangle2.Height = a_.Height;
                 graphicsPath.AddRectangle(rectangle2);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
                 rectangle2.X = a_.Right - m;
                 graphicsPath.AddRectangle(rectangle2);
                 if (!i)
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
                 else
                 {
                     iNBase.a(e.Graphics, rectangle2, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
             }
         }
         if (c != HMIValveType.VT_Valve4 && c != HMIValveType.VT_Valve5 && c != HMIValveType.VT_Valve6)
         {
             if (c == HMIValveType.VT_Valve7)
             {
                 e.Graphics.DrawLine(pen2, rectangle.Left, (rectangle.Top + rectangle.Bottom) / 2, rectangle.Right, (rectangle.Top + rectangle.Bottom) / 2);
                 Rectangle rect = new Rectangle((rectangle.Left + rectangle.Right) / 2 - 3 * rectangle.Width / 8, rectangle.Top - (rectangle.Height / 2 - f - 2), 3 * rectangle.Width / 4, 2 * (rectangle.Height / 2 - f - 2));
                 e.Graphics.DrawArc(pen2, rect, 150f, -120f);
                 rect.Y = (rectangle.Top + rectangle.Bottom) / 2 + f + 2;
                 e.Graphics.DrawArc(pen2, rect, 210f, 120f);
             }
             else if (c == HMIValveType.VT_Valve8)
             {
                 int num = rectangle.Height / 2;
                 if (num > rectangle.Width / 2)
                 {
                     num = rectangle.Width / 2;
                 }
                 e.Graphics.DrawLine(pen2, rectangle.Left, (rectangle.Top + rectangle.Bottom) / 2, (rectangle.Left + rectangle.Right) / 2 - num / 2, (rectangle.Top + rectangle.Bottom) / 2);
                 e.Graphics.DrawLine(pen2, (rectangle.Left + rectangle.Right) / 2 - num / 2, (rectangle.Top + rectangle.Bottom) / 2, (rectangle.Left + rectangle.Right) / 2 + num / 2, (rectangle.Top + rectangle.Bottom) / 2 - num);
                 e.Graphics.DrawLine(pen2, (rectangle.Left + rectangle.Right) / 2 - num / 2, (rectangle.Top + rectangle.Bottom) / 2, (rectangle.Left + rectangle.Right) / 2 + num / 2, (rectangle.Top + rectangle.Bottom) / 2 + num);
                 int num2 = m;
                 if ((double)num2 > (double)num * Math.Sqrt(2.0) / 2.0)
                 {
                     num2 = (int)((double)num * Math.Sqrt(2.0) / 2.0);
                 }
                 int       num3       = (rectangle.Left + rectangle.Right) / 2 - num / 2 + (int)((double)num2 * Math.Sqrt(2.0));
                 Rectangle rectangle3 = new Rectangle(num3 - num2, (rectangle.Top + rectangle.Bottom) / 2 - num2, 2 * num2, 2 * num2);
                 graphicsPath.AddEllipse(rectangle3);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle3, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Sphere, 0, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
                 e.Graphics.DrawLine(pen2, num3 + num2, (rectangle.Top + rectangle.Bottom) / 2, rectangle.Right, (rectangle.Top + rectangle.Bottom) / 2);
             }
             else if (c == HMIValveType.VT_Valve9)
             {
                 Rectangle rectangle4 = new Rectangle(rectangle.Left, rectangle.Top, m, rectangle.Height);
                 graphicsPath.AddRectangle(rectangle4);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle4, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 0, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
                 rectangle4.X     = rectangle.Left + m;
                 rectangle4.Width = rectangle.Width - m;
                 graphicsPath.AddLine(rectangle.Left + m, (rectangle.Top + rectangle.Bottom) / 2, rectangle.Right, rectangle.Top);
                 graphicsPath.AddLine(rectangle.Right, rectangle.Top, rectangle.Right, rectangle.Bottom);
                 graphicsPath.AddLine(rectangle.Right, rectangle.Bottom, rectangle.Left + m, (rectangle.Top + rectangle.Bottom) / 2);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle4, HMIShapeType.ST_Rectangle, graphicsPath, BackColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush3, graphicsPath);
                 }
                 e.Graphics.DrawPath(pen2, graphicsPath);
                 graphicsPath.Reset();
             }
         }
         else
         {
             Rectangle a_2        = new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
             Rectangle rectangle5 = new Rectangle(rectangle.Left + (rectangle.Width - m) / 2, rectangle.Top, m, rectangle.Height);
             if (c == HMIValveType.VT_Valve4)
             {
                 a_2.Y      = rectangle.Bottom - 6 * rectangle.Height / 10;
                 a_2.Height = 6 * rectangle.Height / 10;
             }
             graphicsPath.AddLine((a_2.Left + a_2.Right) / 2, (a_2.Top + a_2.Bottom) / 2, a_2.Left, a_2.Top);
             graphicsPath.AddLine(a_2.Left, a_2.Top, a_2.Left, a_2.Bottom);
             graphicsPath.AddLine(a_2.Left, a_2.Bottom, (a_2.Left + a_2.Right) / 2, (a_2.Top + a_2.Bottom) / 2);
             graphicsPath.AddLine((a_2.Left + a_2.Right) / 2, (a_2.Top + a_2.Bottom) / 2, a_2.Right, a_2.Top);
             graphicsPath.AddLine(a_2.Right, a_2.Top, a_2.Right, a_2.Bottom);
             graphicsPath.AddLine(a_2.Right, a_2.Bottom, (a_2.Left + a_2.Right) / 2, (a_2.Top + a_2.Bottom) / 2);
             if (i)
             {
                 iNBase.a(e.Graphics, a_2, HMIShapeType.ST_Rectangle, graphicsPath, BackColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 90, 0.5f, 0, 0, 0f);
             }
             else
             {
                 e.Graphics.FillPath(solidBrush3, graphicsPath);
             }
             e.Graphics.DrawPath(pen2, graphicsPath);
             graphicsPath.Reset();
             if (c == HMIValveType.VT_Valve4)
             {
                 rectangle5.X      = (a_2.Left + a_2.Right) / 2 - 3 * rectangle.Width / 10;
                 rectangle5.Width  = 6 * rectangle.Width / 10;
                 rectangle5.Y      = rectangle.Top;
                 rectangle5.Height = (a_2.Top + a_2.Bottom) / 2 - rectangle.Top;
                 graphicsPath.AddLine(rectangle5.Left, rectangle5.Top, rectangle5.Right, rectangle5.Top);
                 graphicsPath.AddLine(rectangle5.Right, rectangle5.Top, (rectangle5.Left + rectangle5.Right) / 2, rectangle5.Bottom);
                 graphicsPath.AddLine((rectangle5.Left + rectangle5.Right) / 2, rectangle5.Bottom, rectangle5.Left, rectangle5.Top);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle5, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 0, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
             }
             else if (c != HMIValveType.VT_Valve5)
             {
                 rectangle5.X      = (a_2.Left + a_2.Right) / 2 - m / 2;
                 rectangle5.Width  = m;
                 rectangle5.Y      = (a_2.Top + a_2.Bottom) / 2 - m / 2;
                 rectangle5.Height = m;
                 graphicsPath.AddEllipse(rectangle5);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle5, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Sphere, 0, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
             }
             else
             {
                 rectangle5.X      = (a_2.Left + a_2.Right) / 2 - m / 2;
                 rectangle5.Width  = m;
                 rectangle5.Y      = rectangle.Top;
                 rectangle5.Height = rectangle.Height;
                 graphicsPath.AddRectangle(rectangle5);
                 if (i)
                 {
                     iNBase.a(e.Graphics, rectangle5, HMIShapeType.ST_Rectangle, graphicsPath, ForeColor, Color.White, HMIBkGradientStyle.BKGS_Linear2, 0, 0.5f, 0, 0, 0f);
                 }
                 else
                 {
                     e.Graphics.FillPath(solidBrush2, graphicsPath);
                 }
             }
             e.Graphics.DrawPath(pen2, graphicsPath);
             graphicsPath.Reset();
         }
         if (l != 0)
         {
             e.Graphics.ResetTransform();
             rectangle.X = left;
             rectangle.Y = top;
         }
         pen2.Dispose();
         graphicsPath.Dispose();
         solidBrush2.Dispose();
         solidBrush3.Dispose();
         if (flagB)
         {
             SolidBrush   solidBrush5 = new SolidBrush(Color.Red);
             StringFormat format      = new StringFormat
             {
                 Alignment     = StringAlignment.Center,
                 LineAlignment = StringAlignment.Center
             };
             e.Graphics.DrawString("Designed By Hao Thien Co.,Ltd: 0909.886.483", Font, solidBrush5, base.ClientRectangle, format);
             solidBrush5.Dispose();
         }
     }
     catch (ApplicationException ex)
     {
         SolidBrush solidBrush6 = new SolidBrush(Color.Black);
         e.Graphics.DrawString("The control size is too small", Font, solidBrush6, base.ClientRectangle);
         solidBrush6.Dispose();
         MessageBox.Show(ex.ToString());
     }
 }
Beispiel #31
0
        public override void DrawToGraphics(Graphics graphics)
        {
            Brush      pthGrBrush  = Brushes.Black;
            Pen        pen         = new Pen(Color.Black);
            RectangleF EllipseFill = new RectangleF(AbsoluteX - 2, AbsoluteY - 2, 24, 24);

            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(EllipseFill);

            Brush TextColor = Brushes.Black;

            switch (this.CurrentState)
            {
            case ItemState.Free:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorToFillState());
                if (freeColor != 0)
                {
                    pthGrBrush = new SolidBrush((freeColor > 0) ? getFreeColors[freeColor - 1, 0] : getFreeColors[(-1) * freeColor - 1, 2]);
                }
                break;

            case ItemState.Hover:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorWhenHover());
                TextColor  = Brushes.White;
                break;

            case ItemState.Selected:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorWhenSelected());
                break;

            default:
                break;
            } // switch

            graphics.FillEllipse(pthGrBrush, EllipseFill);
            graphics.DrawEllipse(pen, EllipseFill);

            //1
            switch (_numberOfTokens)
            {
            case 0:
                break;

            case 1:
                EllipseFill = DrawToken(AbsoluteX + 9, AbsoluteY + 9, 4, 4, graphics);
                break;

            case 2:
                EllipseFill = DrawToken(AbsoluteX + 4, AbsoluteY + 9, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 14, AbsoluteY + 9, 4, 4, graphics);
                break;

            case 3:
                EllipseFill = DrawToken(AbsoluteX + 9, AbsoluteY + 4, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 4, AbsoluteY + 14, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 14, AbsoluteY + 14, 4, 4, graphics);
                break;

            case 4:
                EllipseFill = DrawToken(AbsoluteX + 4, AbsoluteY + 4, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 4, AbsoluteY + 14, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 14, AbsoluteY + 4, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 14, AbsoluteY + 14, 4, 4, graphics);
                break;

            case 5:
                EllipseFill = DrawToken(AbsoluteX + 4, AbsoluteY + 4, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 4, AbsoluteY + 14, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 14, AbsoluteY + 4, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 14, AbsoluteY + 14, 4, 4, graphics);
                EllipseFill = DrawToken(AbsoluteX + 9, AbsoluteY + 9, 4, 4, graphics);
                break;

            default:
                RectangleF rect      = new RectangleF(AbsoluteX + 5, AbsoluteY + 5, 18, 18);
                Font       titleFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular, GraphicsUnit.Pixel);
                graphics.DrawString(_numberOfTokens.ToString(), titleFont, new SolidBrush(Color.Black), rect);
                break;
            } // switch

            this.labelItems.labels.Clear();
            this.labelItems.colors.Clear();

            Color color = Color.Black;

            switch (this.CurrentState)
            {
            case ItemState.Hover:
                color = ColorDefinition.GetColorWhenHover();
                break;

            case ItemState.Selected:
                color = ColorDefinition.GetColorWhenSelected();
                break;

            default:
                break;
            } // switch

            if (this.CurrentState == ItemState.Free)
            {
                color = ColorDefinition.GetColorOfName();
            }

            this.labelItems.labels.Add(Name);
            this.labelItems.colors.Add(color);
            this.labelItems.DrawToGraphics(graphics);

            DrawDecorators(graphics);
        }
Beispiel #32
0
        public void DrawSolidCircleAndChangeBrushes(Graphics graphicsMain, int brushesTypeCounter)
        {
            graphicsMain = form1.panelForDisplaying.CreateGraphics();
            graphicsMain.SmoothingMode = SmoothingMode.HighQuality;

            if (brushesTypeCounter == 6)
            {
                brushesTypeCounter = 1;
            }
            switch (brushesTypeCounter)
            {
            case 1:
            {
                SolidBrush mySolidBrush = new SolidBrush(RandomColor.getRandomColor());
                graphicsMain.FillEllipse(mySolidBrush, 50, 50, 100, 100);
                form1.labelDescriptionOfMode.Text = "SolidBrush";
                brushesTypeCounter++;
            } break;

            case 2:
            {
                Random     random           = new Random();
                var        value            = Enum.GetValues(typeof(HatchStyle));
                HatchStyle randomHatchStyle = (HatchStyle)value.GetValue(random.Next(value.Length));

                HatchBrush myHatchBrush = new HatchBrush(randomHatchStyle,
                                                         RandomColor.getRandomColor(), RandomColor.getRandomColor());

                graphicsMain.FillEllipse(myHatchBrush, 50, 50, 100, 100);

                form1.labelDescriptionOfMode.Text = "HatchBrush";
                form1.labelForBrushMode.Text      = randomHatchStyle.ToString();
                brushesTypeCounter++;
            } break;

            case 3:
            {
                TextureBrush myTextureBrush = new TextureBrush(new Bitmap(
                                                                   "D:\\water.jpg"));
                graphicsMain.FillEllipse(myTextureBrush, 50, 50, 100, 100);

                form1.labelDescriptionOfMode.Text = "TextureBrush";
                form1.labelForBrushMode.Text      = "";

                brushesTypeCounter++;
            } break;

            case 4:
            {
                Random             random          = new Random();
                var                values          = Enum.GetValues(typeof(LinearGradientMode));
                LinearGradientMode randLinGradMode = (LinearGradientMode)values.GetValue(random.Next(values.Length));

                LinearGradientBrush myLinGradBrush = new LinearGradientBrush(
                    new Rectangle(50, 50, 100, 100), Color.Black, Color.Blue,
                    randLinGradMode);
                graphicsMain.FillEllipse(myLinGradBrush, 50, 50, 100, 100);

                form1.labelDescriptionOfMode.Text = "LinearGradientBrush";
                form1.labelForBrushMode.Text      = randLinGradMode.ToString();

                brushesTypeCounter++;
                form1.labelForBrushMode.Text = "";
            } break;

            case 5:
            {
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse(50, 50, 100, 100);
                PathGradientBrush myPathGradBrush = new PathGradientBrush(path);
                myPathGradBrush.CenterColor = RandomColor.getRandomColor();
                Color[] myColors = { RandomColor.getRandomColor() };
                myPathGradBrush.SurroundColors = myColors;

                graphicsMain.FillEllipse(myPathGradBrush, 50, 50, 100, 100);

                form1.labelDescriptionOfMode.Text = "PathGradientBrush";
                brushesTypeCounter++;
            } break;
            }
        }
        /// <summary>
        /// Renders the control to an image
        /// </summary>
        private void drawControl(Graphics g, bool on, bool IsBlink)
        {
            Color lightColor;
            Color darkColor;

            if (IsBlink == true)
            {
                lightColor = (on) ? this.BlinkColor : Color.FromArgb(150, this.BlinkDarkColor);
                darkColor  = (on) ? this.BlinkDarkColor : this.BlinkDarkDarkColor;
            }
            else
            {
                lightColor = (on) ? this.Color : Color.FromArgb(150, this.DarkColor);
                darkColor  = (on) ? this.DarkColor : this.DarkDarkColor;
            }
            // Is the bulb on or off


            // Calculate the dimensions of the bulb
            int width  = this.Width - (this.Padding.Left + this.Padding.Right);
            int height = this.Height - (this.Padding.Top + this.Padding.Bottom);
            // Diameter is the lesser of width and height
            int diameter = Math.Min(width, height);

            // Subtract 1 pixel so ellipse doesn't get cut off
            diameter = Math.Max(diameter - 1, 1);

            if (_styles == LedBrghtStyle.Circular)
            {
                // Draw the background ellipse
                var rectangle = new Rectangle(this.Padding.Left, this.Padding.Top, diameter, diameter);
                g.FillEllipse(new SolidBrush(darkColor), rectangle);

                // Draw the glow gradient
                var path = new GraphicsPath();
                path.AddEllipse(rectangle);
                var pathBrush = new PathGradientBrush(path);
                pathBrush.CenterColor    = lightColor;
                pathBrush.SurroundColors = new Color[] { Color.FromArgb(0, lightColor) };
                g.FillEllipse(pathBrush, rectangle);

                // Draw the white reflection gradient
                var offset    = Convert.ToInt32(diameter * .15F);
                var diameter1 = Convert.ToInt32(rectangle.Width * .8F);
                var whiteRect = new Rectangle(rectangle.X - offset, rectangle.Y - offset, diameter1, diameter1);
                var path1     = new GraphicsPath();
                path1.AddEllipse(whiteRect);
                var pathBrush1 = new PathGradientBrush(path);
                pathBrush1.CenterColor    = _reflectionColor;
                pathBrush1.SurroundColors = _surroundColor;
                g.FillEllipse(pathBrush1, whiteRect);

                // Draw the border
                g.SetClip(this.ClientRectangle);
                if (this.Value)
                {
                    g.DrawEllipse(new Pen(Color.FromArgb(85, Color.Black), 1F), rectangle);
                }
            }
            if (_styles == LedBrghtStyle.Rectangular)
            {
                // Draw the background ellipse
                var rectangle = new Rectangle(this.Padding.Left, this.Padding.Top, diameter, diameter);
                g.FillRectangle(new SolidBrush(darkColor), rectangle);

                // Draw the glow gradient
                var path = new GraphicsPath();
                path.AddRectangle(rectangle);
                var pathBrush = new PathGradientBrush(path);
                pathBrush.CenterColor    = lightColor;
                pathBrush.SurroundColors = new Color[] { Color.FromArgb(0, lightColor) };
                g.FillRectangle(pathBrush, rectangle);
            }
        }
Beispiel #34
0
 public override void AddShapePath(GraphicsPath gp, Rectangle rect)
 {
     gp.AddEllipse(rect);
 }
Beispiel #35
0
 /// <summary>
 /// Add an ellipse to the Graphics Path
 /// </summary>
 /// <param name="gpath">The Graphics Path</param>
 /// <param name="rect">The rectangle defining the ellipse to be added</param>
 protected virtual void AddShape(GraphicsPath gpath, Rectangle rect)
 {
     gpath.AddEllipse(rect);
 }
 public Region GetValueRec()
 {
     Region r;
     GraphicsPath gp = new GraphicsPath();
     gp.AddEllipse((float)((.05 - vm.CircleWidth / 200f) * vm.Width), (float)((.05 - vm.CircleWidth / 200f) * vm.Height), (float)(.90 + vm.CircleWidth / 100f) * vm.Width, (float)(.90 + vm.CircleWidth / 100f) * vm.Height);
     r = new Region(gp);
     gp = new GraphicsPath();
     gp.AddEllipse((float)((.05 + vm.CircleWidth / 200f) * vm.Width), (float)((.05 + vm.CircleWidth / 200f) * vm.Height), (float)(.90 - vm.CircleWidth / 100f) * vm.Width, (float)(.90 - vm.CircleWidth / 100f) * vm.Height);
     r.Xor(gp);
     return r;
 }
Beispiel #37
0
    public ColorWheel(Rectangle colorRectangle, Rectangle brightnessRectangle, Rectangle selectedColorRectangle)
    {
        // Caller must provide locations for color wheel
        // (colorRectangle), brightness "strip" (brightnessRectangle)
        // and location to display selected color (selectedColorRectangle).

        using (GraphicsPath path = new GraphicsPath())
        {
            // Store away locations for later use.
            this.colorRectangle = colorRectangle;
            this.brightnessRectangle = brightnessRectangle;
            this.selectedColorRectangle = selectedColorRectangle;
            //this.selectedColor = Color.FromArgb(RGB.Alpha, RGB.Red, RGB.Green, RGB.Blue);

            // Calculate the center of the circle.
            // Start with the location, then offset
            // the point by the radius.
            // Use the smaller of the width and height of
            // the colorRectangle value.
            this.radius = (int)Math.Min(colorRectangle.Width, colorRectangle.Height) / 2;
            this.centerPoint = colorRectangle.Location;
            this.centerPoint.Offset(radius, radius);

            // Start the pointer in the center.
            this.colorPoint = this.centerPoint;

            // Create a region corresponding to the color circle.
            // Code uses this later to determine if a specified
            // point is within the region, using the IsVisible
            // method.
            path.AddEllipse(colorRectangle);
            colorRegion = new Region(path);

            // set { the range for the brightness selector.
            this.brightnessMin = this.brightnessRectangle.Top;
            this.brightnessMax = this.brightnessRectangle.Bottom;

            // Create a region corresponding to the
            // brightness rectangle, with a little extra
            // "breathing room".

            path.AddRectangle(new Rectangle(brightnessRectangle.Left, brightnessRectangle.Top - 10, brightnessRectangle.Width + 10, brightnessRectangle.Height + 20));
            // Create region corresponding to brightness
            // rectangle. Later code uses this to
            // determine if a specified point is within
            // the region, using the IsVisible method.
            brightnessRegion = new Region(path);

            // Set the location for the brightness indicator "marker".
            // Also calculate the scaling factor, scaling the height
            // to be between 0 and 255.
            brightnessX = brightnessRectangle.Left + brightnessRectangle.Width;
            brightnessScaling = (double)255 / (brightnessMax - brightnessMin);

            // Calculate the location of the brightness
            // pointer. Assume it's at the highest position.
            brightnessPoint = new Point(brightnessX, brightnessMax);

            // Create the bitmap that contains the circular gradient.
            CreateGradient();
        }
    }
Beispiel #38
0
	GraphicsPath CreatePath ()
	{
		GraphicsPath path = new GraphicsPath ();
		path.AddEllipse (new Rectangle (20, 20, 100, 100));
		return path;
	}
Beispiel #39
0
            protected override void DrawControl(Graphics g)
            {
                try
                {
                    switch (CtrlStatus.ToolType)
                    {
                    case Enums.eToolType.Rectangle:

                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddRectangle(CtrlPos);
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlRectangle(g);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddRectangle(CtrlPos);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlRectangle(g);
                        }
                        break;

                    case Enums.eToolType.Ellipse:

                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddEllipse(CtrlPos);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlEllipse(g);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddEllipse(CtrlPos);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlEllipse(g);
                        }
                        break;

                    case Enums.eToolType.Triangle:

                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path     = new GraphicsPath();
                            Point        ptLeft   = new Point(CtrlPos.Left, CtrlPos.Bottom);
                            Point        ptCenter = new Point(CtrlPos.Left + CtrlPos.Width / 2, CtrlPos.Top);
                            Point        ptRight  = new Point(CtrlPos.Right, CtrlPos.Bottom);
                            path.AddLine(ptLeft, ptCenter);
                            path.AddLine(ptCenter, ptRight);
                            path.AddLine(ptRight, ptLeft);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlTriangle(g);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path     = new GraphicsPath();
                            Point        ptLeft   = new Point(CtrlPos.Left, CtrlPos.Bottom);
                            Point        ptCenter = new Point(CtrlPos.Left + CtrlPos.Width / 2, CtrlPos.Top);
                            Point        ptRight  = new Point(CtrlPos.Right, CtrlPos.Bottom);
                            path.AddLine(ptLeft, ptCenter);
                            path.AddLine(ptCenter, ptRight);
                            path.AddLine(ptRight, ptLeft);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlTriangle(g);
                        }
                        break;

                    case Enums.eToolType.VerticalLine:

                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddRectangle(CtrlPos);
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Vertical); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlVerticalLine(g);
                            DrawTracker(g, Enums.eLineType.Vertical);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            if (CtrlPos.Width < 2)
                            {
                                CtrlPos = new Rectangle(CtrlPos.X, CtrlPos.Y, 2, CtrlPos.Height);
                            }
                            path.AddRectangle(CtrlPos);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlVerticalLine(g);
                        }
                        break;

                    case Enums.eToolType.HorizontalLine:

                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddRectangle(CtrlPos);
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 3; i <= GetTrackerCount(Enums.eLineType.Horizontal); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlHorizontalLine(g);
                            DrawTracker(g, Enums.eLineType.Horizontal);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            if (CtrlPos.Height < 2)
                            {
                                CtrlPos = new Rectangle(CtrlPos.X, CtrlPos.Y, CtrlPos.Width, 2);
                            }
                            path.AddRectangle(CtrlPos);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlHorizontalLine(g);
                        }
                        break;

                    case Enums.eToolType.PieType1:

                        float     sStartAngle = 270;
                        float     sSweepAngle = 90;
                        Rectangle newRect     = new Rectangle(CtrlPos.X - CtrlPos.Width, CtrlPos.Y, CtrlPos.Width * 2, CtrlPos.Height * 2);
                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect, sStartAngle, sSweepAngle);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect, sStartAngle, sSweepAngle);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect, sStartAngle, sSweepAngle);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect, sStartAngle, sSweepAngle);
                        }
                        break;

                    case Enums.eToolType.PieType2:

                        float     sStartAngle_1 = 0;
                        float     sSweepAngle_1 = 90;
                        Rectangle newRect_1     = new Rectangle(CtrlPos.X - CtrlPos.Width, CtrlPos.Y - CtrlPos.Height, CtrlPos.Width * 2, CtrlPos.Height * 2);
                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect_1, sStartAngle_1, sSweepAngle_1);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect_1, sStartAngle_1, sSweepAngle_1);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect_1, sStartAngle_1, sSweepAngle_1);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect_1, sStartAngle_1, sSweepAngle_1);
                        }
                        break;

                    case Enums.eToolType.PieType3:

                        float     sStartAngle_2 = 90;
                        float     sSweepAngle_2 = 90;
                        Rectangle newRect_2     = new Rectangle(CtrlPos.X, CtrlPos.Y - CtrlPos.Height, CtrlPos.Width * 2, CtrlPos.Height * 2);
                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect_2, sStartAngle_2, sSweepAngle_2);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect_2, sStartAngle_2, sSweepAngle_2);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect_2, sStartAngle_2, sSweepAngle_2);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect_2, sStartAngle_2, sSweepAngle_2);
                        }
                        break;

                    case Enums.eToolType.PieType4:

                        float     sStartAngle_3 = 180;
                        float     sSweepAngle_3 = 90;
                        Rectangle newRect_3     = new Rectangle(CtrlPos.X, CtrlPos.Y, CtrlPos.Width * 2, CtrlPos.Height * 2);
                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect_3, sStartAngle_3, sSweepAngle_3);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect_3, sStartAngle_3, sSweepAngle_3);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddPie(newRect_3, sStartAngle_3, sSweepAngle_3);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlPieType(g, CtrlStatus.ToolType, newRect_3, sStartAngle_3, sSweepAngle_3);
                        }
                        break;

                    case Enums.eToolType.TextType:

                        if (IsSelected == true && IsDesignMode == true)
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddRectangle(CtrlPos);
                            Region meRegion = new Region(path);
                            int    i;
                            for (i = 1; i <= GetTrackerCount(Enums.eLineType.Null); i++)
                            {
                                path.Reset();
                                path.AddRectangle(GetTrackerRect(i));
                                path.CloseFigure();
                                meRegion.Union(path);
                            }
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlText(g);
                            DrawTracker(g, Enums.eLineType.Null);
                        }
                        else
                        {
                            GraphicsPath path = new GraphicsPath();
                            path.AddRectangle(CtrlPos);
                            path.CloseFigure();
                            Region meRegion = new Region(path);
                            this.Region = meRegion;
                            path.Dispose();
                            meRegion.Dispose();

                            DrawCtrlText(g);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "udcCtrlTag.DrawControl()", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
Beispiel #40
0
	protected override void OnPaint(PaintEventArgs pe)
	{
		// Calling the base class OnPaint
		base.OnPaint(pe);
		//GraphicsState oldState = pe.Graphics.Save();
		//pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
		// this prevents jagged edges along the rubber band

		CompassMagnitude();

		Graphics g = pe.Graphics;
		GraphicsPath serge = new GraphicsPath();
		serge.AddEllipse(this.ClientRectangle);
		this.Region = new Region(serge);
		pe.Graphics.FillEllipse(insideColor,
			new Rectangle(0,0,this.Height, this.Width));
		pe.Graphics.DrawLine(rubberBand, offset.X, offset.Y,
			(float)this.Width/2, (float)this.Width/2);
		pe.Graphics.DrawEllipse(Pens.Red,this.Width/3,this.Height/3,this.Width/3,this.Height/3);
		pe.Graphics.DrawEllipse(Pens.Red,this.Width/6,this.Height/6,this.Width-this.Width/3,this.Height-this.Height/3);

		//pe.Graphics.Restore(oldState);
	}
 public GraphicsPath GetValueRec()
 {
     GraphicsPath gp = new GraphicsPath();
     gp.AddEllipse((float)((.04) * vm.Width), (float)((.04) * vm.Height), (float)(.92) * vm.Width, (float)(.92) * vm.Height);
     return gp;
 }
Beispiel #42
0
        // Draw a bar with label & valu using specified index bouned to the
        // specified rectangle of the selected bitmap of specified graphics object
        private void DrawBar(Graphics gr, RectangleF rectBar, HBarData bar)
        {
            // Some calculations
            if (rectBar.Height <= 0)
            {
                rectBar.Height = 1;
            }
            int nAlphaStart = (int)(185 + 5 * rectBar.Width / 24),
                nAlphaEnd   = (int)(10 + 4 * rectBar.Width / 24);

            if (nAlphaStart > 255)
            {
                nAlphaStart = 255;
            }
            else if (nAlphaStart < 0)
            {
                nAlphaStart = 0;
            }

            if (nAlphaEnd > 255)
            {
                nAlphaEnd = 255;
            }
            else if (nAlphaEnd < 0)
            {
                nAlphaEnd = 0;
            }


            Color ColorBacklight    = bar.Colour;
            Color ColorBacklightEnd = Color.FromArgb(50, 0, 0, 0);
            Color ColorGlowStart    = Color.FromArgb(nAlphaEnd, 255, 255, 255);
            Color ColorGlowEnd      = Color.FromArgb(nAlphaStart, 255, 255, 255);
            Color ColorFillBK       = GetDarkerColor(bar.Colour, 85);
            Color ColorBorder       = GetDarkerColor(bar.Colour, 100);

            // Draw a single bar.
            #region BarItself
            RectangleF   er      = new RectangleF(rectBar.Left, rectBar.Top - rectBar.Height / 2, rectBar.Width * 2, rectBar.Height * 2);
            GraphicsPath rctPath = new GraphicsPath();
            rctPath.AddEllipse(er);

            PathGradientBrush pgr = new PathGradientBrush(rctPath);
            pgr.CenterPoint    = new PointF(rectBar.Right, rectBar.Top + rectBar.Height / 2);
            pgr.CenterColor    = ColorBacklight;
            pgr.SurroundColors = new Color[] { ColorBacklightEnd };

            RectangleF          rectGlow = new RectangleF(rectBar.Left, rectBar.Top, rectBar.Width / 2, rectBar.Height);
            LinearGradientBrush brGlow   = new LinearGradientBrush(
                new PointF(rectGlow.Right + 1, rectGlow.Top), new PointF(rectGlow.Left - 1, rectGlow.Top),
                ColorGlowStart, ColorGlowEnd);

            gr.FillRectangle(new SolidBrush(ColorFillBK), rectBar);
            //gr.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), rectBar);
            gr.FillRectangle(pgr, rectBar);
            gr.FillRectangle(brGlow, rectGlow);
            gr.DrawRectangle(new Pen(ColorBorder, 1), rectBar.Left, rectBar.Top, rectBar.Width, rectBar.Height);
            #endregion

            // Draw label
            if (Label.Visible)
            {
                float nLabelHeight = Label.Font.GetHeight(gr);
                gr.DrawString(
                    bar.Label,
                    Label.Font,
                    new SolidBrush(Label.Colour),
                    new RectangleF(
                        rectBar.X,
                        rectBar.Bottom + nBarsGap,
                        rectBar.Width,
                        nLabelHeight));
            }

            // Draw value or %
            if (Values.Visible)
            {
                string strValue = string.Empty;
                if (Values.Mode == CValueProperty.ValueMode.Digit)
                {
                    strValue = bar.Value.ToString("F1");
                }
                else if (Values.Mode == CValueProperty.ValueMode.Percent)
                {
                    double dTotal = bars.TotalValue;
                    if (dTotal > 0)
                    {
                        strValue =
                            ((double)(bar.Value / dTotal)).ToString("P1",
                                                                    System.Globalization.CultureInfo.CurrentCulture);
                    }
                }

                float fValueHeight = Values.Font.GetHeight(gr);
                gr.DrawString(
                    strValue,
                    Values.Font,
                    new SolidBrush(Values.Color),
                    new RectangleF(
                        rectBar.X,
                        rectBar.Top - fValueHeight - 1,
                        rectBar.Width + 2 * nBarsGap,
                        fValueHeight));
            }
        }
Beispiel #43
0
        protected void PaintBackground(PaintEventArgs e, Graphics g, Color tBorder, Color tBottomColorBegin, Color tBottomColorEnd)
        {
            //Set button radius
            int _roundedRadiusX = rectCornerRadius;

            //to avoid 0 rectangle error
            if (buttonRect.Height == 0 && buttonRect.Width == 0)
            {
                SetControlSizes();
            }

            //define control rectangle
            Rectangle r = buttonRect;

            //rectangle for gradient, half upper and lower
            RectangleF halfup   = new RectangleF(r.Left, r.Top, r.Width, r.Height);
            RectangleF halfdown = new RectangleF(r.Left, r.Top + (r.Height / 2) - 1, r.Width, r.Height);

            //start Background
            //for half upper, we paint using linear gradient

            using (GraphicsPath thePath = GetRoundedRect(r, _roundedRadiusX))
            {
                Blend blend = new Blend(4);
                using (LinearGradientBrush lgb = new LinearGradientBrush(halfup, tBottomColorEnd, tBottomColorBegin, 90f, true))
                {
                    blend.Positions = new float[] { 0, 0.18f, 0.35f, 1f };
                    blend.Factors   = new float[] { 0f, .4f, .9f, 1f };
                    lgb.Blend       = blend;
                    g.FillPath(lgb, thePath);
                }

                //for half lower, we paint using radial gradient
                using (GraphicsPath p = new GraphicsPath())
                {
                    p.AddEllipse(halfdown); //make it radial
                    using (PathGradientBrush gradient = new PathGradientBrush(p))
                    {
                        gradient.WrapMode       = WrapMode.Clamp;
                        gradient.CenterPoint    = new PointF(Convert.ToSingle(halfdown.Left + halfdown.Width / 2), Convert.ToSingle(halfdown.Bottom));
                        gradient.CenterColor    = tBottomColorEnd;
                        gradient.SurroundColors = new Color[] { tBottomColorBegin };

                        blend           = new Blend(4);
                        blend.Positions = new float[] { 0, 0.15f, 0.4f, 1f };
                        blend.Factors   = new float[] { 0f, .3f, 1f, 1f };
                        gradient.Blend  = blend;

                        g.FillPath(gradient, thePath);
                    }
                }
                //end Background

                //Begin Borders
                int borderWidth = !highlight ? 1 : 3; //larger if Highlited
                using (GraphicsPath gborderDark = thePath)
                {
                    using (Pen p = new Pen(tBorder, borderWidth))
                    {
                        g.DrawPath(p, gborderDark);
                    }
                    //has focus?
                    if (isHotTracking)
                    {
                        using (Pen p = new Pen(MetroPaint.BorderColor.Button.Hover(Theme), borderWidth))
                        {
                            g.DrawPath(p, gborderDark);
                        }
                    }
                }

                //End Borders
            }
        }
Beispiel #44
0
        /// <summary>
        /// Create a <see cref="GraphicsPath"/> struct for the current symbol based on the
        /// specified scaleFactor and assuming the symbol will be centered at position 0,0.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.</param>
        /// <returns>Returns the <see cref="GraphicsPath"/> for the current symbol</returns>
        public GraphicsPath MakePath(Graphics g, float scaleFactor)
        {
            float scaledSize = (float)(_size * scaleFactor);
            float hsize      = scaledSize / 2,
                  hsize1     = hsize + 1;

            GraphicsPath path = new GraphicsPath();

            switch (_type == SymbolType.Default || (_type == SymbolType.UserDefined && _userSymbol == null) ? Default.Type : _type)
            {
            case SymbolType.Square:
                path.AddLine(-hsize, -hsize, hsize, -hsize);
                path.AddLine(hsize, -hsize, hsize, hsize);
                path.AddLine(hsize, hsize, -hsize, hsize);
                path.AddLine(-hsize, hsize, -hsize, -hsize);
                break;

            case SymbolType.Diamond:
                path.AddLine(0, -hsize, hsize, 0);
                path.AddLine(hsize, 0, 0, hsize);
                path.AddLine(0, hsize, -hsize, 0);
                path.AddLine(-hsize, 0, 0, -hsize);
                break;

            case SymbolType.Triangle:
                path.AddLine(0, -hsize, hsize, hsize);
                path.AddLine(hsize, hsize, -hsize, hsize);
                path.AddLine(-hsize, hsize, 0, -hsize);
                break;

            case SymbolType.Circle:
                path.AddEllipse(-hsize, -hsize, scaledSize, scaledSize);
                break;

            case SymbolType.XCross:
                path.AddLine(-hsize, -hsize, hsize1, hsize1);
                path.StartFigure();
                path.AddLine(hsize, -hsize, -hsize1, hsize1);
                break;

            case SymbolType.Plus:
                path.AddLine(0, -hsize, 0, hsize1);
                path.StartFigure();
                path.AddLine(-hsize, 0, hsize1, 0);
                break;

            case SymbolType.Star:
                path.AddLine(0, -hsize, 0, hsize1);
                path.StartFigure();
                path.AddLine(-hsize, 0, hsize1, 0);
                path.StartFigure();
                path.AddLine(-hsize, -hsize, hsize1, hsize1);
                path.StartFigure();
                path.AddLine(hsize, -hsize, -hsize1, hsize1);
                break;

            case SymbolType.TriangleDown:
                path.AddLine(0, hsize, hsize, -hsize);
                path.AddLine(hsize, -hsize, -hsize, -hsize);
                path.AddLine(-hsize, -hsize, 0, hsize);
                break;

            case SymbolType.HDash:
                path.AddLine(-hsize, 0, hsize1, 0);
                break;

            case SymbolType.VDash:
                path.AddLine(0, -hsize, 0, hsize1);
                break;

            case SymbolType.UserDefined:
                path = _userSymbol.Clone() as GraphicsPath;
                Matrix scaleTransform = new Matrix(scaledSize, 0.0f, 0.0f, scaledSize, 0.0f, 0.0f);
                path.Transform(scaleTransform);
                break;
            }

            return(path);
        }
        private Region DrawCircleInMemory(Point pt1, double radRect)
        {
            GraphicsPath graphics_rect = new GraphicsPath();

            Rectangle ellipse_rect = new Rectangle(pt1.X - (int)radRect, pt1.Y - (int)radRect,
                                                    (int)radRect * 2, (int)radRect * 2);
            graphics_rect.AddEllipse(ellipse_rect);

            return new Region(graphics_rect);
        }
Beispiel #46
-1
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        G = e.Graphics;
        G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

        G.Clear(BackColor);
        G.SmoothingMode = SmoothingMode.AntiAlias;

        GP1 = new GraphicsPath();
        GP1.AddEllipse(0, 2, Height - 5, Height - 5);

        PB1 = new PathGradientBrush(GP1);
        PB1.CenterColor = Color.FromArgb(50, 50, 50);
        PB1.SurroundColors = new Color[] { Color.FromArgb(45, 45, 45) };
        PB1.FocusScales = new PointF(0.3f, 0.3f);

        G.FillPath(PB1, GP1);

        G.DrawEllipse(P1, 0, 2, Height - 5, Height - 5);
        G.DrawEllipse(P2, 1, 3, Height - 7, Height - 7);

        if (_Checked)
        {
            G.FillEllipse(Brushes.Black, 6, 8, Height - 15, Height - 15);
            G.FillEllipse(Brushes.White, 5, 7, Height - 15, Height - 15);
        }

        SZ1 = G.MeasureString(Text, Font);
        PT1 = new PointF(Height - 3, Height / 2 - SZ1.Height / 2);

        G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1);
        G.DrawString(Text, Font, Brushes.White, PT1);
    }