1 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 // Jordi Mas <jordimash@gmail.com>
26 // Graphics PageUnit test sample
32 using System.Drawing.Printing;
33 using System.Drawing.Imaging;
34 using System.Drawing.Drawing2D;
36 public class PrintingMargins
39 public static void Main (string[] args)
41 Bitmap bmp = new Bitmap (600, 600);
42 Graphics gr = Graphics.FromImage (bmp);
43 Rectangle rect = new Rectangle (20, 20, 100, 100);
45 PointF[] polygon_pnts = {new PointF(150.0F, 150.0F),
46 new PointF(200.0F, 125.0F), new PointF(300.0F, 105.0F),
47 new PointF(350.0F, 150.0F), new PointF(400.0F, 200.0F),
48 new PointF(450.0F, 300.0F), new PointF(350.0F, 350.0F) };
\r
52 gr.DrawRectangle (Pens.Red, rect);
53 gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Red, 50, 50);
54 gr.DrawArc (Pens.Red, 30, 30, 60, 60, 0, 180);
55 gr.DrawPolygon (Pens.Red, polygon_pnts);
\r
58 gr.PageUnit = GraphicsUnit.Point;
\r
59 gr.DrawRectangle (Pens.Yellow, rect);
60 gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Yellow, 50, 50);
61 gr.DrawArc (Pens.Yellow, 30, 30, 60, 60, 0, 180);
62 gr.DrawPolygon (Pens.Yellow, polygon_pnts);
65 gr.PageUnit = GraphicsUnit.Document;
\r
66 gr.DrawRectangle (Pens.Pink, rect);
67 gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Pink, 50, 50);
68 gr.DrawArc (Pens.Pink, 30, 30, 60, 60, 0, 180);
69 gr.DrawPolygon (Pens.Pink, polygon_pnts);
72 gr.PageUnit = GraphicsUnit.Inch;
\r
73 gr.DrawRectangle (Pens.Blue, 3f, 1f, 1f, 1f);
74 gr.DrawString ("Unit " + gr.PageUnit, new Font ("Arial", 10), Brushes.Blue, 0.7f, 0.7f);
75 gr.DrawArc (Pens.Blue, 3f, 3f, 1f, 1f, 0, 180);
78 bmp.Save ("units1.bmp");
82 bmp = new Bitmap (600, 600);
83 gr = Graphics.FromImage (bmp);
85 GraphicsPath graphPath = new GraphicsPath();
\r
86 graphPath.AddEllipse (0, 80, 100, 200);
89 gr.DrawBezier (Pens.Red, new Point (10, 10), new Point (20, 10),
90 new Point (35, 50), new Point (50, 10));
92 gr.DrawEllipse (Pens.Red, 10, 50, 30, 50);
\r
93 gr.DrawPath (Pens.Red, graphPath);
94 gr.DrawPie (Pens.Red, 150, 20, 60, 60, 100, 140);
95 gr.DrawCurve (Pens.Red, polygon_pnts, 2, 4, 0.5f);
\r
99 gr.PageUnit = GraphicsUnit.Display;
\r
100 gr.PageUnit = GraphicsUnit.Point;
101 gr.DrawBezier (Pens.Pink, new Point (10, 10), new Point (20, 10),
102 new Point (35, 50), new Point (50, 10));
103 gr.DrawCurve (Pens.Pink, polygon_pnts, 2, 4, 0.5f);
105 gr.DrawEllipse (Pens.Pink, 10, 50, 30, 50);
106 gr.DrawPath (Pens.Pink, graphPath);
107 gr.DrawPie (Pens.Pink, 150, 20, 60, 60, 100, 140);
110 gr.PageUnit = GraphicsUnit.Document;
111 gr.DrawBezier (Pens.Yellow, new Point (10, 10), new Point (20, 10),
112 new Point (35, 50), new Point (50, 10));
114 gr.DrawEllipse (Pens.Yellow, 10, 50, 30, 50);
115 gr.DrawPath (Pens.Yellow, graphPath);
116 gr.DrawPie (Pens.Yellow, 150, 20, 60, 60, 100, 140);
117 gr.DrawCurve (Pens.Yellow, polygon_pnts, 2, 4, 0.5f);
120 gr.PageUnit = GraphicsUnit.Inch;
\r
121 gr.DrawBezier (Pens.Blue, new Point (10, 10), new Point (20, 10),
122 new Point (35, 50), new Point (50, 10));
124 gr.DrawEllipse (Pens.Blue, 10, 50, 30, 50);
125 gr.DrawPath (Pens.Blue, graphPath);
126 gr.DrawPie (Pens.Blue, 150, 20, 60, 60, 100, 140);
127 gr.DrawCurve (Pens.Blue, polygon_pnts, 2, 4, 0.5f);
129 bmp.Save ("units2.bmp");