Esempio n. 1
0
        /// <summary>
        /// Draws a shadow around a rectangle.
        /// </summary>
        /// <param name="g">The current Graphics handle.</param>
        /// <param name="origin">The rectangle which should have a shadow.</param>
        /// <param name="startAngle">The start angle.</param>
        /// <param name="sweepAngle">The sweep angle.</param>
        /// <param name="color">The color of the shadow.</param>
        /// <param name="dx">The horizontal shift.</param>
        /// <param name="dy">The vertical shift.</param>
        /// <param name="blur">The blurness.</param>
        public static void DrawPieShadow(this System.Drawing.Graphics g, Rectangle origin, float startAngle, float sweepAngle, Color color, float dx, float dy, float blur)
        {
            var gp = new GraphicsPath();

            gp.AddPie(origin, startAngle, sweepAngle);

            if (gp.PointCount > 0)
            {
                g.DrawShadow(gp, color, dx, dy, blur);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draws a shadow around a rectangle.
        /// </summary>
        /// <param name="g">The current Graphics handle.</param>
        /// <param name="origin">The rectangle which should have a shadow.</param>
        /// <param name="color">The color of the shadow.</param>
        /// <param name="dx">The horizontal shift.</param>
        /// <param name="dy">The vertical shift.</param>
        /// <param name="blur">The blurness.</param>
        public static void DrawCircularShadow(this System.Drawing.Graphics g, RectangleF origin, Color color, float dx, float dy, float blur)
        {
            var gp = new GraphicsPath();

            gp.AddEllipse(origin);

            if (gp.PointCount > 0)
            {
                g.DrawShadow(gp, color, dx, dy, blur);
            }
        }
        /// <summary>
        /// An event handler called when drawing the annotation on the specified graphics object.
        /// </summary>
        /// <param name="graphics">The graphics object.</param>
        protected override void OnDraw(Graphics graphics)
        {
            // Call the base class method.
            base.OnDraw(graphics);

            // If the message is not visible, do nothing.
            if (!this.Visible) return;

            // Use a normal smoothing mode.
            graphics.SmoothingMode = SmoothingMode.Default;

            // Create the pen.
            using (Pen pen = new Pen(this.borderColor))
            {
                // Create the brush.
                using (SolidBrush brush = new SolidBrush(this.backgroundColor))
                {
                    // Draw the shadow.
                    graphics.DrawShadow(this.shadow, this.BorderRectangle);
                    // Draw the rectangle.
                    graphics.FillRectangle(brush, this.BorderRectangle);
                    // Draw the border.
                    graphics.DrawRectangle(pen, this.BorderRectangle);
                }
            }

            // Display a message.
            TextRenderer.DrawText(graphics, this.text, this.font, this.BorderRectangle, this.textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
        }
        // Protected methods.
        /// <summary>
        /// An event handler called when drawing the annotation on the specified graphics object.
        /// </summary>
        /// <param name="graphics">The graphics object.</param>
        protected override void OnDraw(Graphics graphics)
        {
            // If the message is not visible, do nothing.
            if (!this.Visible) return;

            // Use a normal smoothing mode.
            graphics.SmoothingMode = SmoothingMode.HighQuality;

            // Create the pen.
            using (Pen pen = new Pen(this.BorderColor))
            {
                // Create the brush.
                using (SolidBrush brush = new SolidBrush(this.BackgroundColor))
                {
                    // Draw the shadow.
                    graphics.DrawShadow(this.Shadow, this.textRectangle);
                    // Draw the polygon.
                    graphics.FillPolygon(brush, this.polygon);
                    // Draw the border.
                    graphics.DrawPolygon(pen, this.polygon);
                }
            }

            // Display a message.
            TextRenderer.DrawText(graphics, this.Text, this.Font, this.textRectangle, this.TextColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
        }
Esempio n. 5
0
        protected static void DrawText(Graphics g, Rectangle rect, string text, ContentAlignmentEx alignment, bool multiline, Font font, Color color, Color shadow, ShadowMask mask)
        {
            if (multiline == false)
            {
                var rc = alignment.CalcTextRect(g.MeasureString(text, font), rect);

                if (mask != ShadowMask.None)
                {
                    g.DrawShadow(text, font, shadow, rc.X, rc.Y, mask);
                }

                using (var brush = new SolidBrush(color))
                {
                    g.DrawString(text, font, brush, rc.X, rc.Y);
                }
            }
            else
            {
                var texts = g.GetMultilineText(text, font, rect.Width);
                var textSize = g.CalcMultilineTextSize(texts, font);

                var rc = alignment.CalcTextRect(textSize, rect);
                using (var brush = new SolidBrush(color))
                {
                    var top = rc.Top;
                    foreach (var line in texts)
                    {
                        var size = g.MeasureString(String.IsNullOrEmpty(line) ? " " : line, font);
                        var rcLine = alignment.CalcTextRect(size, rc.Left, top, rc.Width, size.Height);

                        if (mask != ShadowMask.None)
                        {
                            g.DrawShadow(text, font, shadow, rcLine.X, rcLine.Y, mask);
                        }

                        g.DrawString(line, font, brush, rcLine.X, rcLine.Y);

                        top += rcLine.Height;
                    }
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Draws a shadow around a rectangle.
 /// </summary>
 /// <param name="g">The current Graphics handle.</param>
 /// <param name="path">The path which should have a shadow.</param>
 /// <param name="color">The color of the shadow.</param>
 /// <param name="shift">The horizontal and vertical shift.</param>
 /// <param name="blur">The blurness.</param>
 public static void DrawShadow(this System.Drawing.Graphics g, GraphicsPath path, Color color, PointF shift, float blur)
 {
     g.DrawShadow(path, color, shift.X, shift.Y, blur);
 }