Example #1
0
        protected virtual void DrawBadgeLabel(Graphics graphics, Size size, string badgeLabel)
        {
            var rect = new Rectangle(size);

            rect.Inflate(-2, -2);
            graphics.FillEllipse(Brushes.Red(Generator), rect);
            graphics.DrawEllipse(new Pen(Colors.White, 2, Generator), rect);
            var font          = new Font(SystemFont.Bold, 10);
            var labelSize     = graphics.MeasureString(font, badgeLabel);
            var labelPosition = ((PointF)(rect.Size - labelSize) / 2) + rect.Location;

            graphics.DrawText(font, Colors.White, labelPosition, badgeLabel);
            graphics.Flush();
        }
Example #2
0
        Control PathClip()
        {
            var control = new Drawable {
                Size = new Size(350, 250)
            };

            control.Paint += (sender, e) => {
                using (Generator.Context)
                {
                    var path = new GraphicsPath();
                    path.AddEllipse(25, 25, 50, 50);
                    path.AddRectangle(125, 25, 50, 50);
                    path.AddLines(new PointF(225, 25), new PointF(225, 75), new PointF(275, 50));
                    path.CloseFigure();

                    e.Graphics.SetClip(path);
                    if (ResetClip)
                    {
                        e.Graphics.ResetClip();
                    }
                    e.Graphics.FillRectangle(Brushes.Blue(), path.Bounds);

                    path.Transform(Matrix.FromTranslation(0, 75));
                    e.Graphics.SetClip(path);
                    if (ResetClip)
                    {
                        e.Graphics.ResetClip();
                    }
                    e.Graphics.FillRectangle(Brushes.Red(), path.Bounds);

                    path.Transform(Matrix.FromTranslation(0, 75));
                    e.Graphics.SetClip(path);
                    if (ResetClip)
                    {
                        e.Graphics.ResetClip();
                    }
                    e.Graphics.FillRectangle(Brushes.Green(), path.Bounds);
                }
            };
            PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "ResetClip")
                {
                    control.Invalidate();
                }
            };
            return(control);
        }
Example #3
0
        Control RectangleClip()
        {
            var control = new Drawable {
                Size = new Size(300, 100)
            };

            control.Paint += (sender, e) => {
                using (Generator.Context)
                {
                    e.Graphics.SetClip(new RectangleF(25, 25, 50, 50));
                    if (ResetClip)
                    {
                        e.Graphics.ResetClip();
                    }
                    e.Graphics.FillRectangle(Brushes.Blue(), new RectangleF(25, 0, 100, 100));

                    e.Graphics.SetClip(new RectangleF(125, 25, 50, 50));
                    if (ResetClip)
                    {
                        e.Graphics.ResetClip();
                    }
                    e.Graphics.FillRectangle(Brushes.Red(), new RectangleF(125, 0, 100, 100));

                    e.Graphics.SetClip(new RectangleF(225, 25, 50, 50));
                    if (ResetClip)
                    {
                        e.Graphics.ResetClip();
                    }
                    e.Graphics.FillRectangle(Brushes.Green(), new RectangleF(225, 0, 100, 100));
                }
            };
            PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "ResetClip")
                {
                    control.Invalidate();
                }
            };
            return(control);
        }