Ejemplo n.º 1
0
        protected void PaintSignImage(IGraphics g, PointF pos, SizeF sz)
        {
            Graphics underlayGraphics = (Graphics)g.UnderlayGraphics;
            Image    image            = this.cachedSignImage;

            if (this.Opacity != 1.0)
            {
                image = (Image) new Bitmap(this.cachedSignImage);
                ImageHelper.ApplyAlpha(image as Bitmap, Convert.ToSingle(this.Opacity));
            }
            underlayGraphics.DrawImageUnscaledAndClipped(image, Rectangle.Round(new RectangleF(pos, sz)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Paints the sign
        /// </summary>
        /// <param name="g">The IGraphics to use fo painting the sign</param>
        /// <param name="signRect">Rectangle containing sign bounds</param>
        protected virtual void PaintSign(IGraphics g, Rectangle signRect)
        {
            Rectangle signRealRectangle = Rectangle.Empty;

            if (this.SignStyle == SignStyles.Image)
            {
                if (cachedSignImage != null)
                {
                    int centerX = Math.Max(0, (this.Size.Width - cachedSignImage.Width) / 2);
                    int centerY = Math.Max(0, (this.Size.Height - cachedSignImage.Height) / 2);

                    Point pos = new Point(Math.Max(0, centerX), Math.Max(0, centerY));
                    pos.X = Math.Min(pos.X, this.Size.Width);
                    pos.Y = Math.Min(pos.Y, this.Size.Height);
                    Size sz = new Size(
                        Math.Min(this.Size.Width, cachedSignImage.Size.Width),
                        Math.Min(this.Size.Height, cachedSignImage.Size.Height));

                    Graphics rawGraphics = (Graphics)g.UnderlayGraphics;

                    Image imageToDraw = cachedSignImage;

                    if (this.Opacity != 1)
                    {
                        imageToDraw = new Bitmap(cachedSignImage);
                        ImageHelper.ApplyAlpha(imageToDraw as Bitmap, Convert.ToSingle(this.Opacity));
                    }

                    rawGraphics.DrawImageUnscaledAndClipped(imageToDraw, new Rectangle(pos, sz));
                    signRealRectangle = new Rectangle(pos, sz);
                }
            }
            else
            {
                if (signRect.Width <= SignWidth || signRect.Height <= SignWidth)
                {
                    return;
                }

                using (Pen pen = new Pen(this.ForeColor, SignWidth))
                {
                    pen.Alignment = PenAlignment.Inset;
                    Graphics gr = (Graphics)g.UnderlayGraphics;

                    if (this.SignStyle == SignStyles.PlusMinus)
                    {
                        if (this.Expanded)
                        {
                            gr.DrawLine(pen, signRect.Left, signRect.Top + signRect.Height / 2, signRect.Right, signRect.Top + signRect.Height / 2);
                        }
                        else
                        {
                            gr.DrawLine(pen, signRect.Left, signRect.Top + signRect.Height / 2, signRect.Right, signRect.Top + signRect.Height / 2);
                            gr.DrawLine(pen, signRect.Left + signRect.Width / 2, signRect.Top, signRect.Left + signRect.Width / 2, signRect.Bottom);
                        }
                    }
                    else if (this.SignStyle == SignStyles.Arrow)
                    {
                        if (this.Expanded)
                        {
                            gr.DrawLine(pen, signRect.Left, signRect.Bottom, signRect.Left + signRect.Width / 2, signRect.Top);
                            gr.DrawLine(pen, signRect.Left + signRect.Width / 2, signRect.Top, signRect.Right, signRect.Bottom);
                        }
                        else
                        {
                            gr.DrawLine(pen, signRect.Left, signRect.Top, signRect.Left + signRect.Width / 2, signRect.Bottom);
                            gr.DrawLine(pen, signRect.Left + signRect.Width / 2, signRect.Bottom, signRect.Right, signRect.Top);
                        }
                    }
                    else if (this.SignStyle == SignStyles.Triangle)
                    {
                        using (SolidBrush brush = new SolidBrush(this.ForeColor))
                        {
                            if (this.Expanded)
                            {
                                Point point1 = new Point(signRect.X, signRect.Bottom);
                                Point point2 = new Point(signRect.Right, signRect.Bottom);
                                Point point3 = new Point(signRect.X + signRect.Width / 2, signRect.Y);

                                Point[] trianglePoints = new Point[] { point1, point2, point3 };

                                gr.FillPolygon(brush, trianglePoints);
                            }
                            else
                            {
                                Point point1 = new Point(signRect.X, signRect.Y);
                                Point point2 = new Point(signRect.X + signRect.Width / 2, signRect.Bottom);
                                Point point3 = new Point(signRect.Right, signRect.Y);

                                Point[] trianglePoints = new Point[] { point1, point2, point3 };

                                gr.FillPolygon(brush, trianglePoints);
                            }
                        }
                    }
                }
            }
        }