2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / System.Drawing / Samples / System.Drawing / GraphicsUnits.cs
1 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
2 //
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:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
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.
21 //
22 //
23 // Author:
24 //      Jordi Mas <jordimash@gmail.com>
25 //
26 // Graphics PageUnit test sample
27 //
28
29 using System;
30 using System.Drawing;
31 using System.IO;
32 using System.Drawing.Printing;
33 using System.Drawing.Imaging;
34 using System.Drawing.Drawing2D;
35
36 public class PrintingMargins
37 {
38
39         public static void Main (string[] args)
40         {
41                 Bitmap  bmp = new Bitmap (600, 600);
42                 Graphics gr = Graphics.FromImage (bmp);
43                 Rectangle rect = new Rectangle (20, 20, 100, 100);
44
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
49
50
51                 // Default Display\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
56
57                 // Point\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);
63
64                 // Document\r
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);
70
71                 // Inc\r
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);
76
77 \r
78                 bmp.Save ("units1.bmp");
79                 bmp.Dispose ();
80                 gr.Dispose ();
81
82                 bmp = new Bitmap (600, 600);
83                 gr = Graphics.FromImage (bmp);
84
85                 GraphicsPath graphPath = new GraphicsPath();\r
86                 graphPath.AddEllipse (0, 80, 100, 200);
87
88                 // Default Display\r
89                 gr.DrawBezier (Pens.Red, new Point (10, 10), new Point (20, 10),
90                         new Point (35, 50), new Point (50, 10));
91
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
96
97
98                 // Point
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);
104
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);
108
109                 // Document\r
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));
113
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);
118
119                 // Inc\r
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));
123
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);
128
129                 bmp.Save ("units2.bmp");
130         }
131 }
132
133