void DrawSample(Graphics graphics) { using (graphics.Generator.Context) { graphics.FillRectangle(Brushes.Green(), 0, 0, 200, 200); if (UseGraphicsPathClip) { var path = GraphicsPath.GetRoundRect(new RectangleF(10, 10, 180, 180), 20); graphics.SetClip(path); } else { graphics.SetClip(new RectangleF(10, 10, 180, 180)); } if (UseClearColor) { graphics.Clear(new SolidBrush(new Color(Colors.Red, 0.5f))); } else { graphics.Clear(); } graphics.FillEllipse(Brushes.Blue(), 25, 25, 150, 150); } }
public static void Draw(Graphics graphics) { var generator = graphics.Generator; var image = TestIcons.TestImage(generator); // lines var whitePen = Pens.White(generator); graphics.DrawLine(whitePen, 1, 1, 99, 99); graphics.DrawLine(whitePen, 50, 1, 50, 99); graphics.DrawLine(whitePen, 1, 51, 99, 51); graphics.DrawRectangle(Pens.White(generator), 101, 1, 100, 100); graphics.DrawRectangle(Pens.White(generator), 101, 1, 10, 10); graphics.DrawEllipse(Pens.Green(generator), 101, 1, 100, 100); graphics.DrawPolygon(Pens.White(generator), new PointF(203, 1), new PointF(253, 51), new Point(203, 101), new PointF(203, 1), new PointF(253, 1), new PointF(253, 101), new PointF(203, 101)); var rect = new RectangleF(255, 1, 100, 100); graphics.DrawArc(Pens.LightGreen(generator), rect, 180, 90); graphics.DrawArc(Pens.SkyBlue(generator), rect, 0, 90); rect.Inflate(-15, 0); graphics.DrawArc(Pens.FloralWhite(generator), rect, -45, 90); rect.Inflate(-5, -20); graphics.DrawArc(Pens.SlateGray(generator), rect, -45, 270); rect.Inflate(-10, -10); graphics.DrawArc(Pens.SteelBlue(generator), rect, 180 + 45, 270); graphics.DrawImage(image, 100, 1, 100, 100); graphics.DrawText(Fonts.Sans(12 * graphics.PointsPerPixel, generator: generator), Colors.White, 0, 104, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); // filled graphics.FillRectangle(Brushes.White(generator), 101, 120, 100, 100); graphics.FillRectangle(Brushes.Gray(generator), 101, 120, 10, 10); graphics.FillEllipse(Brushes.Green(generator), 101, 120, 100, 100); graphics.FillPolygon(Brushes.White(generator), new PointF(202, 120), new PointF(252, 170), new Point(202, 220), new PointF(202, 120)); rect = new RectangleF(255, 120, 100, 100); graphics.FillPie(Brushes.LightGreen(generator), rect, 180, 90); graphics.FillPie(Brushes.SkyBlue(generator), rect, 0, 90); rect.Inflate(-15, 0); graphics.FillPie(Brushes.FloralWhite(generator), rect, -45, 90); rect.Inflate(-5, -20); graphics.FillPie(Brushes.SlateGray(generator), rect, -45, 270); rect.Inflate(-10, -10); graphics.FillPie(Brushes.SteelBlue(generator), rect, 180 + 45, 270); graphics.DrawImage(image, 101, 120, 100, 100); }
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); }
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); }