//--------------------------------------------- // BasketballGrid.cs © 2004 by Charles Petzold //--------------------------------------------- using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class BasketballGrid: PrintableForm { public new static void Main() { Application.Run(new BasketballGrid()); } public BasketballGrid() { Text = "Basketball Grid"; } protected override void DoPage(Graphics grfx, Color clr, int cx, int cy) { grfx.PageUnit = GraphicsUnit.Inch; grfx.PageScale = 0.1f; Pen pnThin = new Pen(Brushes.Black, 0.025f); Pen pnThick = new Pen(Brushes.Black, 0.075f); float xOffset = 2f; float yOffset = 5; int iRange = 80; GraphicsPath path = new GraphicsPath(); path.AddRectangle(new RectangleF(0, yOffset + 58, 41 + xOffset, 45)); Region reg = new Region(path); reg.Complement(new Rectangle(0, 0, 120, 120)); grfx.Clip = reg; for (int x = 0; x <= 80; x++) { Pen pn = pnThin; if (x % 5 == 0) pn = pnThick; if (x != 0 && x % 10 == 0) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Far; grfx.DrawString(x.ToString(), Font, Brushes.Black, x + xOffset, yOffset, sf); sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Center; grfx.DrawString(x.ToString(), Font, Brushes.Black, xOffset, x + yOffset, sf); } grfx.DrawLine(pn, x + xOffset, yOffset, x + xOffset, iRange + yOffset); grfx.DrawLine(pn, xOffset, x + yOffset, iRange + xOffset, x + yOffset); } grfx.DrawLine(pnThin, xOffset, yOffset, 80 + xOffset, 80 + yOffset); grfx.ResetClip(); iRange = 40; for (int x = 60; x <= 100; x++) { Pen pn = pnThin; if (x % 5 == 0) pn = pnThick; if (x % 10 == 0) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Far; // Across if (x != 60) grfx.DrawString(x.ToString(), Font, Brushes.Black, x + xOffset - 60, yOffset + 60, sf); sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Center; // Down grfx.DrawString(x.ToString(), Font, Brushes.Black, xOffset, x + yOffset, sf); } // Vertical grfx.DrawLine(pn, x + xOffset - 60, yOffset + 60, x + xOffset - 60, iRange + yOffset + 60); // Horizontal grfx.DrawLine(pn, xOffset, x + yOffset, iRange + xOffset, x + yOffset); } grfx.DrawLine(pnThin, xOffset, yOffset + 60, iRange + xOffset, iRange + 60 + yOffset); } }