2 // Test application for some graphics.cs functions implementation
5 // Jordi Mas i Hernàndez, jordi@ximian.com
9 using System.Drawing.Imaging;
11 using System.Drawing.Drawing2D;
14 public class graphicsUI
17 public static void Main( )
20 Bitmap bmp = new Bitmap(500, 250);
21 Graphics dc = Graphics.FromImage(bmp);
23 Pen BluePen = new Pen(Color.Blue, 3);
24 Pen GreenPen = new Pen(Color.Green, 3);
25 Pen RedPen = new Pen(Color.Red, 3);
26 SolidBrush redBrush = new SolidBrush(Color.Red);
27 SolidBrush blueBrush = new SolidBrush(Color.Blue);
34 dc.DrawRectangle(BluePen, x,y,50,50);
36 dc.DrawEllipse(RedPen, x, y, 70, 50);
37 dc.DrawArc (BluePen, x, y, 50, 40, (float)0, (float)120);
40 dc.DrawBezier (GreenPen, new Point(x, y+5), new Point(x+50, y+5),
41 new Point(x+20, y+20), new Point(x+50, y+50));
45 PointF point1 = new PointF(10.0F+x, 10.0F);
46 PointF point2 = new PointF(10.0F+x, 5.0F);
47 PointF point3 = new PointF(40.0F+x, 5.0F);
48 PointF point4 = new PointF(50.0F+x, 10.0F);
49 PointF point5 = new PointF(60.0F+x, 20.0F);
50 PointF point6 = new PointF(70.0F+x, 40.0F);
51 PointF point7 = new PointF(50.0F+x, 50.0F);
52 PointF[] curvePoints ={point1,point2,point3, point4,point5, point6, point7};
53 dc.DrawLines(RedPen, curvePoints);
55 FillMode aFillMode = FillMode.Alternate;
56 dc.DrawClosedCurve(GreenPen, curvePoints, tension, aFillMode);
61 PointF point10 = new PointF(x, y+15.0F);
62 PointF point20 = new PointF(x+40.0F, y+10.0F);
63 PointF point30 = new PointF(x+50.0F, y+40.0F);
64 PointF point40 = new PointF(x+10.0F, y+30.0F);
65 PointF[] points = {point10, point20, point30, point40};
66 FillMode newFillMode = FillMode.Winding;
67 dc.FillClosedCurve(redBrush, points, newFillMode, tension);
69 // Fill pie to screen.
70 dc.FillPie(blueBrush, x, 0, 200.0F, 100.0f, 300.0F, 45.0F);
76 // Clipping and Graphics container test
77 dc.SetClip(new Rectangle(5+x, 5+y, 75, 75));
79 // Begin a graphics container.
80 GraphicsContainer container = dc.BeginContainer();
82 // Set an additional clipping region for the container.
83 dc.SetClip(new Rectangle(50+x, 25+y, 50, 37));
85 // Fill a red rectangle in the container.
86 dc.FillRectangle(redBrush, 0, 0, 200, 200);
88 dc.EndContainer(container);
89 SolidBrush blueBrushLight = new SolidBrush(Color.FromArgb(128, 0, 0, 255));
90 dc.FillRectangle(blueBrushLight, 0, 0, 200, 200);
93 Pen blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 2.0f);
94 dc.DrawRectangle(blackPen, 5+x, 5+y, 75, 75);
95 dc.DrawRectangle(blackPen, 50+x, 25+y, 50, 37);
101 Point[] ptstrans = {new Point(x, y), new Point(50+x, 25+y)};
102 dc.DrawLine(BluePen, ptstrans[0], ptstrans[1]);
103 dc.TranslateTransform(40.0F, 30.0F);
104 dc.TransformPoints(CoordinateSpace.Page,CoordinateSpace.World,ptstrans);
106 dc.DrawLine(RedPen, ptstrans[0], ptstrans[1]);
108 bmp.Save("graphicsui.bmp", ImageFormat.Bmp);