当前位置: 首页>>代码示例>>C#>>正文


C# System.Drawing.Drawing2D.GraphicsPath.AddPath方法代码示例

本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddPath方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.GraphicsPath.AddPath方法的具体用法?C# System.Drawing.Drawing2D.GraphicsPath.AddPath怎么用?C# System.Drawing.Drawing2D.GraphicsPath.AddPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Drawing2D.GraphicsPath的用法示例。


在下文中一共展示了System.Drawing.Drawing2D.GraphicsPath.AddPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawLabel

        /// <summary>
        /// Draws labels in a specified rectangle
        /// </summary>
        /// <param name="g">The graphics object to draw to</param>
        /// <param name="labelText">The label text to draw</param>
        /// <param name="labelBounds">The rectangle of the label</param>
        /// <param name="symb">the Label Symbolizer to use when drawing the label</param>
        private static void DrawLabel(Graphics g, string labelText, RectangleF labelBounds, ILabelSymbolizer symb)
        {
            //Sets up the brushes and such for the labeling
            Brush foreBrush = new SolidBrush(symb.FontColor);
            Font textFont = symb.GetFont();
            StringFormat format = new StringFormat();
            format.Alignment = symb.Alignment;
            Pen borderPen = new Pen(symb.BorderColor);
            Brush backBrush = new SolidBrush(symb.BackColor);
            Brush haloBrush = new SolidBrush(symb.HaloColor);
            Pen haloPen = new Pen(symb.HaloColor);
            haloPen.Width = 2;
            haloPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Outset;
            Brush shadowBrush = new SolidBrush(symb.DropShadowColor);

            //Text graphics path
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString(labelText, textFont.FontFamily, (int)textFont.Style, textFont.SizeInPoints * 96F / 72F, labelBounds, format);

            //Draws the text outline
            if (symb.BackColorEnabled && symb.BackColor != Color.Transparent)
            {
                if (symb.FontColor == Color.Transparent)
                {
                    System.Drawing.Drawing2D.GraphicsPath backgroundGP = new System.Drawing.Drawing2D.GraphicsPath();
                    backgroundGP.AddRectangle(labelBounds);
                    backgroundGP.FillMode = System.Drawing.Drawing2D.FillMode.Alternate;
                    backgroundGP.AddPath(gp, true);
                    g.FillPath(backBrush, backgroundGP);
                    backgroundGP.Dispose();
                }
                else
                {
                    g.FillRectangle(backBrush, labelBounds);
                }
            }

            //Draws the border if its enabled
            if (symb.BorderVisible && symb.BorderColor != Color.Transparent)
                g.DrawRectangle(borderPen, labelBounds.X, labelBounds.Y, labelBounds.Width, labelBounds.Height);

            //Draws the drop shadow                      
            if (symb.DropShadowEnabled && symb.DropShadowColor != Color.Transparent)
            {
                System.Drawing.Drawing2D.Matrix gpTrans = new System.Drawing.Drawing2D.Matrix();
                gpTrans.Translate(symb.DropShadowPixelOffset.X, symb.DropShadowPixelOffset.Y);
                gp.Transform(gpTrans);
                g.FillPath(shadowBrush, gp);
                gpTrans = new System.Drawing.Drawing2D.Matrix();
                gpTrans.Translate(-symb.DropShadowPixelOffset.X, -symb.DropShadowPixelOffset.Y);
                gp.Transform(gpTrans);
            }

            //Draws the text halo
            if (symb.HaloEnabled && symb.HaloColor != Color.Transparent)
                g.DrawPath(haloPen, gp);

            //Draws the text if its not transparent
            if (symb.FontColor != Color.Transparent)
                g.FillPath(foreBrush, gp);

            //Cleans up the rest of the drawing objects
            shadowBrush.Dispose();
            borderPen.Dispose();
            foreBrush.Dispose();
            backBrush.Dispose();
            haloBrush.Dispose();
            haloPen.Dispose();
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:76,代码来源:MapLabelLayer.cs

示例2: Paint

        /// <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(MapWindow.Main.Global.ColorFromHSL(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 0.6 * Highlight), 1.75F);
            Color gradientTop = MapWindow.Main.Global.ColorFromHSL(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 0.7 * Highlight);
            Color gradientBottom = MapWindow.Main.Global.ColorFromHSL(Color.GetHue(), Color.GetSaturation(), Color.GetBrightness() * 1.0 * Highlight);

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

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

                //Draws the basic shape
                System.Drawing.Rectangle fillRectange = new Rectangle(0, 0, this.Width - 5, this.Height - 5);
                System.Drawing.Drawing2D.GraphicsPath fillArea = GetRoundedRect(fillRectange, 5);
                System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(fillRectange, gradientBottom, gradientTop, System.Drawing.Drawing2D.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, this.Width);
                RectangleF textRect;
                if ((textSize.Width < this.Width) || (textSize.Height < this.Height))
                    textRect = new RectangleF((this.Width - textSize.Width) / 2, (this.Height - textSize.Height) / 2, textSize.Width, textSize.Height);
                else
                    textRect = new RectangleF(0, (this.Height - textSize.Height) / 2, this.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, System.Drawing.Brushes.Black, textRect);

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

            //Draws Ellipse Shapes
            if (_shape == ModelShapes.Ellipse)
            {
                //Draws the shadow
                shadowPath.AddEllipse(0, 5, this.Width+5, this.Height);
                System.Drawing.Drawing2D.PathGradientBrush shadowBrush = new System.Drawing.Drawing2D.PathGradientBrush(shadowPath);
                shadowBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                shadowBrush.InterpolationColors = colorBlend;
                graph.FillPath(shadowBrush, shadowPath);

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

                //Draws the text
                SizeF textSize = graph.MeasureString(_name, _font, this.Width);
                RectangleF textRect;
                if ((textSize.Width < this.Width) || (textSize.Height < this.Height))
                    textRect = new RectangleF((this.Width - textSize.Width) / 2, (this.Height - textSize.Height) / 2, textSize.Width, textSize.Height);
                else
                    textRect = new RectangleF(0, (this.Height - textSize.Height) / 2, this.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, System.Drawing.Brushes.Black, textRect);

                //Garbage collection
                myBrush.Dispose();
            }

            //Draws Triangular Shapes
            if (_shape == ModelShapes.Triangle)
            {
                //Draws the shadow
                Point[] ptShadow = new Point[4];
                ptShadow[0] = new Point(5, 5);
                ptShadow[1] = new Point(this.Width + 5, ((this.Height - 5) / 2) + 5);
                ptShadow[2] = new Point(5, this.Height+2);
                ptShadow[3] = new Point(5, 5);
                shadowPath.AddLines(ptShadow);
                System.Drawing.Drawing2D.PathGradientBrush shadowBrush = new System.Drawing.Drawing2D.PathGradientBrush(shadowPath);
                shadowBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                shadowBrush.InterpolationColors = colorBlend;
                graph.FillPath(shadowBrush, shadowPath);
//.........这里部分代码省略.........
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:101,代码来源:ModelElement.cs


注:本文中的System.Drawing.Drawing2D.GraphicsPath.AddPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。